2

I am migrating an application from struts1 to struts2. I have a use case here. Struts1 action adds query String in the URL like this:

 public String execute() throws Exception {
     ..... some code here.....
     ActionForward inputForward = HttpRedirector.getRedirectToInput(request,
     mapping, "id=" + request.getParameter("id") + "&" + 
     request.getQueryString(), filterForm);

     return inputForward;

 }

when it redirects to input page url is modified like this:

http://localhost:8084/struts2App/board.jsp?id=1&null

Similarly I have to add Query String in my struts2 action url. Currently my struts2 action url looks like this when i submit the form:

localhost:8084/struts2App/board.action

And I want to modify it, the same way it is done in struts1 like this:

http://localhost:8084/struts2App/board.action?id=1&null

Here is the struts2 action mapping

    <action name="board*" class="com.nextjet.web.hud.BoardAction">
        <result name="success">/board.jsp</result>
        <result name="input">/board.jsp</result>
    </action>

Can someone tell me how to achieve it.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Vishal Patidar
  • 191
  • 2
  • 9

1 Answers1

1

You can return redirect result:

<action name="board*" class="com.nextjet.web.hud.BoardAction">
    <result name="success">/board.jsp</result>
    <result name="input">/board.jsp</result>
    <result name="redirect" type="redirectAction">
      <param name="actionName"><![CDATA[${'board.action?'+ parameters}]]></param>
    </result>
</action>

You should have getter for parameters:

public String getParameters(){
   return "id=" + request.getParameter("id") + "&" + request.getQueryString();
}
Roman C
  • 49,761
  • 33
  • 66
  • 176