Struts2 2.3.1 token Exception occurred during processing request: null
使用 token 时出错项目使用的开发包版本
struts2-core-2.3.8.jar
xwork-core-2.3.8.jar
页面
index.jsp
<body>
<s:form action="act" method="post">
姓名:<s:textfield name="name"/><s:token></s:token>
<input type="submit" value="发送"/>
</s:form>
</body>
message.jsp
<body>
<s:property value="name"/>
<br/><%=new Date() %>
</body>
后台包含的类代码
package test;
public class PersonAction{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String execute(){
return "message";
}
}
struts.xml配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- <constant name="struts.action.extension" value="do,action,html" /> -->
<constant name="struts.ui.theme" value="易做图" />
<package name="many" namespace="" extends="struts-default">
<action name="act*" method="{1}" class="test.PersonAction">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="token"/>
<result name="invalid.token">index.jsp</result>
<result name="message">message.jsp</result>
</action>
</package>
</struts>
struts struts2 token exception --------------------编程问答-------------------- <s:form action="act" method="post">改为
三月 08, 2013 10:19:03 上午 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Form token 1G2MLT77455L3EDKT5B88J55CVTV9HBP does not match the session token null.
三月 08, 2013 10:19:03 上午 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: Exception occurred during processing request: null
java.lang.NullPointerException
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:630)
at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:606)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:210)
at com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:139)
at org.apache.struts2.interceptor.TokenInterceptor.getErrorMessage(TokenInterceptor.java:182)
at org.apache.struts2.interceptor.TokenInterceptor.handleInvalidToken(TokenInterceptor.java:166)
at org.apache.struts2.interceptor.TokenInterceptor.handleToken(TokenInterceptor.java:151)
at org.apache.struts2.interceptor.TokenInterceptor.doIntercept(TokenInterceptor.java:142)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
<s:form action="actexecute" method="post"> --------------------编程问答-------------------- 这个第一次访问的时候是正常的访问之后刷新才出错 --------------------编程问答--------------------
这个第一次访问的时候是正常的访问之后刷新才出错 --------------------编程问答-------------------- NullPointerException,说明不能重复提交。第二次不能提交,当然就是空指针异常了。可以配置试图,或者进行友好提示,比如提交按钮置灰等。 --------------------编程问答--------------------
我不是配置了struts里面的token,按正常程序应该是跳转那个index.jsp的而且我测试
xwork-core-2.1.6.jar
struts2-core-2.1.8.jar
这个包下运行是正常的
--------------------编程问答-------------------- 在jsp上加上 <s:actionerror />
<s:token></s:token>改为<s:token/>
试下,看显示的什么信息 --------------------编程问答--------------------
--------------------编程问答--------------------
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:630)
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:606)
就是那个500 --------------------编程问答-------------------- <result name="invalid.token">/index.jsp</result>
<result name="message">/message.jsp</result> --------------------编程问答--------------------
这样也不行
大神,要不我把源码发给你试试? --------------------编程问答-------------------- 给个邮箱或者qq
--------------------编程问答-------------------- ftp://lastpring@221.231.138.75/wwwroot/down/struts2.rar
这是一个正确版本一个错误版本的源码,求大神有空给看一下到底啥原因哇· --------------------编程问答-------------------- 参考下:
http://www.iteye.com/topic/399518 --------------------编程问答--------------------
谢谢,好了 --------------------编程问答-------------------- 今天也遇到了和你同样的问题,我用的是struts-core-2.3.12,xwork-core-2.3.12的包,后来经过我的测试,你可以把你的action继承ActionSupport,这样这个问题就可以解决了。呵呵,虽然发现的比较晚,但是希望还是对你有帮助。虽然找到了原因,但是还真的不知道为什么要这样做。估计只有继承ActionSupport,token的易做图才会起作用吧。 --------------------编程问答--------------------
果然,我之前是implements Action出现了和楼主一样的错误,改了extends ActionSupport,就好了。 --------------------编程问答--------------------
但是更苦逼的事出现了,单独这样用还行,如果一旦struts与spring一整合就悲剧了,提交后的第一次重复提交还会正常运行,第二次以后的所有重复提交都会出现No result defined for action action.LoginAction and result input的错误,郁闷了哦,最后只好把action的class设为包括包名的全称,但这样又没和spring整合在一起,苦逼哦 --------------------编程问答--------------------
我知道我哪里错了,Spring的Bean是单例模式,而action是每一次请求就生成一个action,我去 --------------------编程问答--------------------
me too
补充:Java , Web 开发