Tutorial :struts2 forward to different pages


I have view.jsp and edit.jsp pages. Both call load() method of an action, which returns SUCCESS. Is there a way to forward to the page request came from in struts.xml, instead of this?

<action name="call_1" method="load" class="package.action.List">    <result name="success" type="json">/WEB-INF/view.jsp</result>  </action>  <action name="call_2" method="load" class="package.action.List">    <result name="success" type="json">/WEB-INF/edit.jsp</result>  </action>  

Also, my action builds hashmap as {"3":"adam","1":"brian","2":"brit","4":"den"}, which is used to populate a drop down menu. It is sorted based on values, but for some reason json still dispaly it in the following order. brian->brit->adam->den. Why is still being sorted based on keys when keys are strings.


Yes, you can use wildcard mappings to condense your two <action> definitions into one.

<action name="list-*" method="load" class="package.action.List">      <result name="success" type="json">/WEB-INF/{1}.jsp</result>  </action>  

The above will take the part after the hyphen in the action request URL and use it set the result location. You could then call it with either of these two URLs:

http://yourapp.com/list-view.action  http://yourapp.com/list-edit.action  

As for sorting your JSON object, you can read this answer for more details on how to create a comparator and get it in the order you want.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »