Redirect to another action in an interceptor in struts 2

后端 未结 3 1864
花落未央
花落未央 2021-02-03 11:38

I am currently in the process of learning Struts 2 and I am currently building a simple application where unverified users are redirected to a login form.

I have a login

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-03 12:19

    The standard way is to return a special global result (eg "login") and define a global mapping from that result to your admin/login.jsp. So you just must add this line:

    if(user == null) {
          return "login";
    }
    

    And in your struts.xml:

    
       /admin/login.jsp
    
    

    BTW, I'm afraid that you are replacing the default Struts2 interceptor stack with your single interceptor, normally you want to add your interceptor to the stack. Eg:

    
     
    
     
      
      
     
    
    
    

    BTW2: You must NOT apply the interceptor to your login action, of course.

提交回复
热议问题