日期:2014-05-18  浏览次数:20826 次

使用doFilter过滤 JSP不能编译
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:572)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:36)


源程序如下:


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   javax.servlet.http.HttpServletRequest;

public   class   EncodingFilter   implements   Filter   {
        protected   FilterConfig   filterconfig;
        private   String   targetEncoding   =   "gb2312 ";

        public   void   init(FilterConfig   config)   throws   ServletException   {
                this.filterconfig   =   config;
                this.targetEncoding   =   config.getInitParameter( "encoding ");

        }

        public   void   doFilter(ServletRequest   srequest,   ServletResponse   sresponse,
                        FilterChain   chain)   throws   IOException,   ServletException   {
                HttpServletRequest   request   =   (HttpServletRequest)srequest;
                request.setCharacterEncoding(targetEncoding);
                chain.doFilter(srequest,sresponse);
               

        }
       
        public   void   setFilterConfig(final   FilterConfig   filterConfig){
                this.filterconfig=filterConfig;
        }

        public   void   destroy()   {
                this.filterconfig   =   null;

        }

}



------解决方案--------------------
不是说:com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:36)
有错误吗?请把行号标出来
------解决方案--------------------
最好设个断点自己跟踪下看看在哪出的异常。
另外我这的一份filte