<s:token > </s:token>
在jsp頁面的form里面加上 注意:要先訪問到這個jsp頁面,來給token初始的值,這樣當(dāng)你提交的時候,才能匹配上
剛進(jìn)入jsp頁面的時候,struts2會生成一個tokenid的字符串,然后存入session。當(dāng)點擊提交按鈕的時候,struts2把頁面 的tokenid回傳到struts2的攔截器里,看看是否一樣,一樣的話,就在給tokenid賦個新值,然后傳回表單,當(dāng)再點擊提交或者刷新的時 候,又執(zhí)行上面的過程,結(jié)果session中的tokenid和表單中的不一樣,就出錯
<action name="xxx" class="xxx">
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<result name="invalid.token" type="dispatcher" >/jsp/repeatRefresh.jsp</result>
<result name="input" type="dispatcher" >/jsp/Person.jsp</result>
<result name="success" type="dispatcher" >/jsp/Person.jsp</result>
</action>
<interceptor-ref name="token"/>
<interceptor-ref name="defaultStack"/>
<result name="invalid.token" type="dispatcher" >/jsp/repeatRefresh.jsp</result>
<result name="input" type="dispatcher" >/jsp/Person.jsp</result>
<result name="success" type="dispatcher" >/jsp/Person.jsp</result>
</action>
上面的invalid.token默認(rèn)是不一致時候的result,這樣就返回到repeatRefresh.jsp頁面,在這里給出提示,比如:不能重復(fù)提交等等
別忘了在頁面的form里加上 <s:token > </s:token>,可以查看源代碼,就能找到tokenid的值