org.apache.catalina.connector.Request.parseParameters(Request.java:2446) NullPointerException异常处理

1、环境

tomcat6.0.8 + jdk6 + struts1 

2、问题的产生

页面有两个异常的请求

http://127.0.0.1/project/a.action?do=testA&m=10
http://127.0.0.1/project/a.action?do=testB&m=10

两个请求几乎同步到达server。结果出现异常:

java.lang.NullPointerException
	at org.apache.catalina.connector.Request.parseParameters(Request.java:2446)
	at org.apache.catalina.connector.Request.getParameter(Request.java:1040)
	at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:355)
	at com.tepper.common.util.JsonUtil.jsonResponse(JsonUtil.java:101)
	at com.tepper.flow.action.TechnologyFlowAction.loadLinkers(TechnologyFlowAction.java:126)
	at com.tepper.flow.action.TechnologyFlowAction.judgeRequest(TechnologyFlowAction.java:86)
	at com.tepper.flow.action.TechnologyFlowAction.execute(TechnologyFlowAction.java:59)
	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
	at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.tepper.common.SessionFilter.doFilter(SessionFilter.java:76)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.tepper.common.ResFilter.doFilter(ResFilter.java:49)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
	at java.lang.Thread.run(Thread.java:619)

或者后台没异常,前台第一个请求的response返回的是第二个请求的结果。而第二次请求则没有response。

经调试,发现两次请求的request对象是同一对象。然后想起Struts1是非线程安全的,而我在代码中,为了让一个Action接收多个页面的请求,把request对象写成了全局对象。

3、解决

struts1是非线程安全的。两个同一时间的异步请求,会得到同一个request对象,两个请求会造成冲突。

在execution方法中使用局部变量是最简单的保证线程安全的方法了。也就是说在使用struts1的action时,不要在类中定义属性。

把全局的request对象,放回execution方法中,变成局部变量,问题得到解决。

时间: 2024-10-21 09:55:43

org.apache.catalina.connector.Request.parseParameters(Request.java:2446) NullPointerException异常处理的相关文章

请教个问题。搞了半天也不知道怎么解决 org.apache.catalina.core.StandardWrapperValve invoke

问题描述 出现这个样的错误该怎么样解决啊,网上说的不太明白是什么意思org.apache.catalina.core.StandardWrapperValveinvoke我的连接数据库这样写的packageorg.zjy.db;importjava.sql.*;//该用来负责与数据库之间的连接,同时执行Sql语句publicclassDBUtil{privatestaticConnectionconn=null;privatestaticStatementst=null;//该方法用来获取与数据

Unhandled Exception thrown: class java.lang.NullPointerException

问题描述 WARN:2011-04-0417:15:29,906:RequestProcessor[line:538}:UnhandledExceptionthrown:classjava.lang.NullPointerExceptionjavax.servlet.ServletExceptionatorg.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)atorg.apache.

java web java.lang.NullPointerException

问题描述 java web java.lang.NullPointerException 严重: Servlet.service() for servlet [selectServlet] in context with path [/Exercise] threw exceptionjava.lang.NullPointerException at DB.DataBaseConnection.selectOperation1(DataBaseConnection.java:45) at Ser

servlet-关于java.lang.NullPointerException的问题

问题描述 关于java.lang.NullPointerException的问题 提示的错误是:严重: Servlet.service() for servlet Shopping threw exceptionjava.lang.NullPointerException at cn.itcast.Shopping.doGet(Shopping.java:45) at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) at

mybatis-myBatis中的莫名其妙的java.lang.NullPointerException,求指教

问题描述 myBatis中的莫名其妙的java.lang.NullPointerException,求指教 xml: <!-- ognl访问静态方法的表达式 为@class@method(args),以下为调用Ognl.isNotEmpty()方法,还有其它方法如isNotBlank()可以使用,具体请查看Ognl类 --> AND SRLNO = '${h_srlno}' AND URGEDATE = '${h_date}' </where> </sql> <s

axis-AxisFault 错误 java.lang.NullPointerException

问题描述 AxisFault 错误 java.lang.NullPointerException 报错行是UserInfo userinfo = (UserInfo) call.invoke(new Object[] {sid,sysno,ip }); AxisFault faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException faultSubcode: faultString: java.lang.N

最近运行别人项目的时候,java.lang.NullPointerException 但是看了半天也不知道那个地方空指针了

问题描述 Struts Problem ReportStruts has detected an unhandled exception:Messages: File: com/lingx/system/security/SecurityContextFactory.javaLine number: 28Stacktracesjava.lang.NullPointerException com.lingx.system.security.SecurityContextFactory.getUse

org.apache.catalina.loader.WebappClassLoader loadClass问题

2014-3-31 16:30:00 org.apache.catalina.loader.WebappClassLoader loadClass 信息: Illegal access: this web application instance has been stopped already.  Could not load org.quartz.StatefulJob.  The eventual following stack trace is caused by an error th

struts2-org.apache.catalina.core.StandardContext filterStart

问题描述 org.apache.catalina.core.StandardContext filterStart 2014-3-28 21:20:53 org.apache.catalina.core.AprLifecycleListener init 信息: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java