I am coding login module, based on the role I want to return different action. I am having code for the different actions in my struts.xml:
if (role == 1) {
Sysyem.out.println("I am a admin");
return "adminaction";
} else if (role == 2) {开发者_如何学运维
Sysyem.out.println("I am a Manager");
return "adminaction";
} else if (role == 3) {
Sysyem.out.println("I am a BA");
return "adminaction";
}
Is there any other way to handle this struts 2. In struts 1 we used to do it by actionforward. We assign some value to action forward and finally return it.
youractionClass
if (role == 1) {
Sysyem.out.println("I am a admin");
return "admin";
} else if (role == 2) {
Sysyem.out.println("I am a Manager");
return "manager";
} else if (role == 3) {
Sysyem.out.println("I am a BA");
return "ba";
}
Now inside struts.xml simply mention the string in the name
attribute of result
as follows
<action name="loginAction" class="youractionClass">
<result name="admin" type="redirect">adminaction</result>
<result name="manager" type="redirect">managerAction</result>
<result name="ba" type="redirect">baAction</result>
</action>
精彩评论