简体   繁体   中英

how to return different actions in struts2

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>

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM