SetCharacterEncodingFilter很麻烦空值异常问题,大家帮忙看看

07-03-09 deancheng
我的tomcat服务器运行后,日志信息里记录着程序一直在抛出这个异常:

2007-03-09 00:54:11 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception

java.lang.NullPointerException

at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:372)

at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)

at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)

at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)

at filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:28)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)

at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)

at java.lang.Thread.run(Thread.java:595)

根据堆栈看,好象是说我的 字符集过滤类的 doFilter 方法的空值异常

但是这个类我实在是找不的参数传递的都是 容器对象,涉及到tomcat更底层支持类,我找不出解决错误的方法,请大家帮帮忙。小弟不胜感激!

1
deancheng
2007-03-09 10:51
根据堆栈看,好象是说我的 字符集过滤类的 doFilter 方法的空值异常

但是这个类我不清楚,因为参数传递的都是 容器对象,涉及到tomcat更底层支持类,我找不出解决错误的方法,请大家帮帮忙。小弟不胜感激!

SetCharacterEncodingFilter.java

package filters;

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

public class SetCharacterEncodingFilter implements Filter{

protected String encoding = null ;

protected FilterConfig filterConfig = null ;

protected boolean ignore = true ;

public void destroy(){

this.encoding = null ;

this.filterConfig = null ;

}

public void doFilter( ServletRequest request , ServletResponse response , FilterChain chain)

throws IOException , ServletException{

if (ignore || (request.getCharacterEncoding() == null)){

String encoding = selectEncoding(request);

if (encoding != null)

request.setCharacterEncoding(encoding);

}

chain.doFilter(request , response);

}

public void init(FilterConfig filterConfig) throws ServletException{

this.filterConfig = filterConfig ;

this.encoding = filterConfig.getInitParameter("encoding");

String value = filterConfig.getInitParameter("ignore");

if (value == null)

this.ignore = true ;

else if (value.equalsIgnoreCase("true"))

this.ignore = true ;

else if (value.equalsIgnoreCase("yes"))

this.ignore = true ;

else

this.ignore = false ;

}

protected String selectEncoding( ServletRequest request){

return this.encoding;

}

}

java类的第28行:

chain.doFilter(request , response);

感觉应该是说chain 这个对象是空的。但不知道怎么解决。请大家给点意见。

[该贴被deancheng于2007年03月09日 10:52修改过]

banq
2007-03-10 12:23
不是setCha问题,它只是一个filter,因此会在错误中出现,关键错误是:

processForwardConfig

这可能是struts的配置或代码中有关forward是出错,在这个节点周围检查错误。

deancheng
2007-03-12 17:16
谢谢banq 老师的指点,我把 forward 又重新核对了一下,没有发现什么异常,对于 forward 的结果页面,我都核查了,没有发现错误。现在把 struts-config.xml贴出来,您有时间的话帮忙看看,谢谢。

<?xml version="1.0" encoding="UTF-8"?>

<struts-config>

<data-sources />

<!-- ========== Form Bean Definitions =================================== -->

<form-beans type="org.apache.struts.action.ActionFormBean">

<form-bean name="SelfCompanyForm" type="com.szhtp.besttoneweb.form.SelfCompanyForm"/>

<form-bean name="NewsinfoForm" type="com.szhtp.besttoneweb.form.NewsinfoForm"/>

<form-bean name="FeedbackinfoForm" type="com.szhtp.besttoneweb.form.FeedbackinfoForm"/>

<form-bean name="AlterHotCompanyInfoForm" type="com.szhtp.besttoneweb.form.AlterHotCompanyInfoForm"/>

<form-bean name="QAUSelfEnterCompanyInfoForm" type="com.szhtp.besttoneweb.form.QAUSelfEnterCompanyInfoForm"/>

<form-bean name="UcompanyinfoForm" type="com.szhtp.besttoneweb.form.UcompanyinfoForm"/>

<form-bean name="UpdateUserInfoForm" type="com.szhtp.besttoneweb.form.UpdateUserInfoForm"/>

<form-bean name="PretrasactBusinessInfoForm" type="com.szhtp.besttoneweb.form.PretrasactBusinessInfoForm"/>

<form-bean name="FoodTechInfoForm" type="com.szhtp.besttoneweb.form.FoodTechInfoForm"/>

<form-bean name="CavilInfoForm" type="com.szhtp.besttoneweb.form.CavilInfoForm"/>

<form-bean name="PlatinaHotelForm" type="com.szhtp.besttoneweb.form.PlatinaHotelForm"/>

<form-bean name="ChnneltypeForm" type="com.szhtp.besttoneweb.form.ChnneltypeForm"/>

</form-beans>

<global-exceptions />

<global-forwards>

<forward name="systemError" path="" redirect="false" contextRelative="true">

</forward>

</global-forwards>

<action-mappings >

接下面

[该贴被deancheng于2007年03月12日 17:17修改过]

[该贴被deancheng于2007年03月12日 17:18修改过]

猜你喜欢