4 Nov 2015

How to Get Action Name in JSP Using Struts2

Some single page applications/modules need to check the user's action (URL) before displaying the content corresponding to the action.

Consider we have 2 URL's as:
      www.j2eekart.com/addPerson
      www.j2eekart.com/editPerson

For the both URL's same jsp page will be displayed, say it as Person.jsp. But, when addPerson URL is requested we have to display Add Person button and for editPerson URL we have to display Edit Person button inside this jsp. In this case it is needed to check the requested action name to display its corresponding content.

You can get action name from the context inside a jsp as:
<s:if test="#context['struts.actionMapping'].name=='addPerson'">
   <input id="addPerson" type="button" value="Add Person" />
</s:if>
<s:elseif test="#context['struts.actionMapping'].name=='editPerson'">
   <input id="editPerson" type="button" value="Edit Person" />
</s:elseif>


Also, check:
How to Get Requested Action (URL) Name in Struts2





Popular Posts

Write to Us
Name
Email
Message