Unable to implement Struts 2 token interceptor with hyperlink

前端 未结 2 602
挽巷
挽巷 2020-12-01 17:14

I tried to implement token interceptor with the tag but its showing error on the first click. i.e The form has already been processed or

2条回答
  •  抹茶落季
    2020-12-01 17:53

    The s:token tag merely places a hidden element that contains the unique token.

    There's not need to use token with url, because the form should be submitted. If you want to pass some token as a parameter then you need to use s:param tag.

    Define the parameter

      private String token;
    
      public String getToken() {
        return token;
      }
    
      public void setToken(String token) {
        this.token = token;
      }
    
      public String execute() throws Exception {
        Map context = ActionContext.getContext().getValueStack().getContext();
        Object myToken = context.get("token");
        if (myToken == null) {
            myToken = TokenHelper.setToken("token");
            context.put("token", myToken);
        }
        token = myToken.toString();
        return SUCCESS;
      }
    

    in the JSP

    
    

提交回复
热议问题