I'm developing a login page for users, users with admin priviledge are forwarded to a specific path, and users with user privledge are forwarded to another path. I want to forward after processing the java class. I'm new to Struts 2.
Best Regards,
The easiest solution is to just declare a different result for each user type.
<action name="login">
<result name="admin">/WEB-INF/admin_home.jsp</result>
<result name="user">/WEB-INF/user_home.jsp</result>
<result name="input">/WEB-INF/login.jsp</result>
</action>
An actionRedirect
is likely more desirable, implementing the post-redirect-get pattern.
There are a few other options, including using an action variable to decide which to go to. For example, if you exposed an action property which
:
<action name="login">
<result>/WEB-INF/${which}_home.jsp</result>
<result name="input">/WEB-INF/login.jsp</result>
</action>
By Forward if you mean to redirect user to different page? if this is the case than all you have to set the result string in your action like
public class MyActionextends ActionSupport{
String action="default"
//getter and setter for action
public String execute() throws Exception {
String view;
if admin
view="admin_view"
action="admin_view"
if user
view="user"
action="user"
return view;
}
]
in struts.xml
do something like
<action name="myaction">
<result name="user">user.jsp</result>
<result name="admin_view">admin.jsp</result>
</action>
What dave has suggested
<action name="myaction">
<result>/WEB-INF/${action}_home.jsp</result>
<result name="input">/WEB-INF/login.jsp</result>
</action>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.