0

I am a beginner to struts2. i am using struts2 token interceptor to prevent CSRF. the token interceptor in working for the login page, but it is not working for the second page. the second page is just a JSP with hyperlinks, and when i change the token value it says "Could not find token name in params" . this is my code

Jsp

<div style="margin: 0 auto; font-size: 16px;">


<s:token />
<a href="<s:url value="view"  />" >Click Here to View and Search Data</a>
<br/><br/> 
<a href="<s:url value="Upload.jsp"  />" >Click here to Upload Data (CSV format)</a>
<br/><br/> 
<a href="<s:url value="Register.jsp"  />" >Click here to Upload Data (FORM)</a>

  </div>

Struts.xml

<package name="default" extends="struts-default, json-default">    
    <!-- CREATING INTERCEPTOR -->

    <interceptors>
        <interceptor-stack name="myStack">
            <interceptor-ref name="defaultStack" />
            <interceptor-ref name="tokenSession" />  
            <interceptor-ref name="timer"/>
            <interceptor-ref name="logger"/>  
            <interceptor-ref name="fileUpload" />                                    
        </interceptor-stack>
    </interceptors>

    <default-interceptor-ref name="myStack"/>

    <global-results>
        <result name="invalid.token">/error.jsp</result>
    </global-results>
    <action name="login" class="action.loginAction">
        <result name="input">/Login.jsp</result>
        <result name="success">/Main.jsp</result>
        <result name="error">/error.jsp</result>           
    </action>

how do i implement token intercepto for this jsp.

please suggest

anonymous
  • 244
  • 2
  • 4
  • 23

2 Answers2

0

Try changing order of interceptors , keep defaultStack in last.

<interceptors>
    <interceptor-stack name="myStack">
        <interceptor-ref name="tokenSession" />  
        <interceptor-ref name="timer"/>
        <interceptor-ref name="logger"/>  
        <interceptor-ref name="fileUpload" />
        <interceptor-ref name="defaultStack" />                                    
    </interceptor-stack>
</interceptors>
0

Try using token instead of tokenSession.

<interceptor-ref name="token" />

Also post the struts mapping for second page submit.