Apache Struts 2: Redirecting to a link and another Action
Apache Struts is a project developing an open-source web application framework for Java EE web application development that promotes a model–view–controller (MVC) architectural approach through extensions the Java Servlet web API. [Definition from Wikipedia]
To know more about Apache Struts 2, click here.
Redirect To JSP Page
It is very simple to redirect to a JSP(JavaServer Pages) which is a technology that helps software developers create dynamically generated web pages based on HTML, XML, or other document types.
<ACTION NAME=”LOGIN” CLASS=”LOGINACTION”>
<RESULT NAME=”INPUT”>LOGIN.JSP</RESULT>
</ACTION>
Redirect To Action
Assuming that you have an Action called LoginAction and HomeAction,
<ACTION NAME=”LOGIN” CLASS=”LOGINACTION”>
<RESULT NAME=”SUCCESS” TYPE=”REDIRECTACTION”>
<PARAM NAME=”ACTIONNAME”>HOME</PARAM>
</RESULT>
</ACTION><ACTION NAME=”HOME” CLASS=”HOMEACTION”>
<RESULT NAME=”SUCCESS”>HOME.JSP</RESULT>
</ACTION>
You can also pass parameters to an action while redirecting and call another Page if the input are not provided in the initial page like this.
<action name=”login” class=”LoginAction”>
<result name=”success” type=”redirectAction”>
<param name=”actionName”>home</param>
<param name=”userName”>${userName}</param>
</result>
<result name=”input”>login.jsp</result>
</action>
Description:
If LoginAction returns “success” then go to “home” action (which calls HomeAction).
If input values are not properly provided to LoginAction and it returns “input” or “Action.INPUT”, then open login.jsp
.