用System.out.println();检测那个对象是空的,你没有代码,只有这样了

解决方案 »

  1.   

    package com.dareway.apps.common.webcontroller;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;import com.dareway.apps.common.GlobalNames;public class EncodingFilter
        implements Filter
    {    protected String encoding;
        protected FilterConfig filterConfig;    public EncodingFilter()
        {
            encoding = null;
            filterConfig = null;
        }    public void destroy()
        {
            encoding = null;
            filterConfig = null;
        }    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException
        {
            if(encoding != null){
             String contentType = request.getContentType();
             if(contentType != null){
             String[] contentTypeTem = contentType.split(";");
             contentTypeTem = contentTypeTem[contentTypeTem.length-1].split("=");
             if(contentTypeTem.length == 2 && "UTF-8".equalsIgnoreCase(contentTypeTem[1])){
             request.setCharacterEncoding("UTF-8");
             }else {
             request.setCharacterEncoding(encoding);
             }
             }else {
             request.setCharacterEncoding(encoding);
             }
            }else{
             request.setCharacterEncoding(GlobalNames.DEFAULT_ENCODING);
            }
            chain.doFilter(request, response);
        }    public void init(FilterConfig filterConfig)
            throws ServletException
        {
            this.filterConfig = filterConfig;
            encoding = filterConfig.getInitParameter(GlobalNames.ENCODING);
        }
    }这是EncodingFilter的代码?
    异常发生在chain.doFilter(request, response);
    这个地方。
    第二:
    这是dofilter的内容,每个请求都会走这一步的。web.xml中的配置
    <filter>
    <filter-name>Encoding</filter-name>
    <filter-class>com.dareway.apps.common.webcontroller.EncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GBK</param-value>
    </init-param>
    </filter>
    而且点按钮是不固定的 有时候是这个按钮,有时候是另外一个。而且就算某一个按钮报了异常,然后重新点击时异常就不会出现了。
      

  2.   

    我的Hibernate 也是这问题 ,不知道 怎么搞呀,