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;    }}

解决方案 »

  1.   

    不是说:com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:36)
    有错误吗?请把行号标出来
      

  2.   

    最好设个断点自己跟踪下看看在哪出的异常。
    另外我这的一份filter源码是继承了HttpServlet的
    public class SetCharacterEncodingFilter extends HttpServlet implements Filter
      

  3.   

    这个错误的意思不是说doFilter有错,
    而是doFilter发现了你的jsp有错,
    好好在jsp里面找找,
    或者贴出来让大家帮你找~
      

  4.   

    Unable to compile class for JSP类不能为当前的jsp页面编译成功.说明你的jsp页面或者后台代码有错com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:36) 指的是哪里?
      

  5.   

    第36 行      chain.doFilter(srequest,sresponse);
      

  6.   

    Jsp文件非常简单 C.JSP
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %><%@ page contentType="text/html; charset=gb2312" language="java" %><html><head>  
    <title>JSTL:的使用</title></head><body bgcolor="#FFFFFF">
      <c:set var="test" value="sdkfjksdj" scope="request"/>
      <c:redirect url="re.jsp"><c:param name="userName" value="sdklfjsdklj">  </c:param>
    </c:redirect>
    </body>
    </html>
    re.jsp
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %><%@ page contentType="text/html; charset=gb2312" language="java" %><c:out value="${param.userName}"/>
      

  7.   

    lz修改两个jsp页面中的代码如下:
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
      

  8.   

    lz页面中jstl标签库的uri地址写的不正确。
      

  9.   

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    前面有一个JSP的路径 我写漏了