开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜