使用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)
有错误吗?请把行号标出来
[解决办法]
最好设个断点自己跟踪下看看在哪出的异常。
另外我这的一份filter源码是继承了HttpServlet的
public class SetCharacterEncodingFilter extends HttpServlet implements Filter
[解决办法]
这个错误的意思不是说doFilter有错,
而是doFilter发现了你的jsp有错,
好好在jsp里面找找,
或者贴出来让大家帮你找~
[解决办法]
Unable to compile class for JSP
类不能为当前的jsp页面编译成功.说明你的jsp页面或者后台代码有错
com.jspdev.ch8.EncodingFilter.doFilter(EncodingFilter.java:36) 指的是哪里?
[解决办法]
lz修改两个jsp页面中的代码如下:
<%@ taglib prefix= "c " uri= "http://java.sun.com/jsp/jstl/core " %>
[解决办法]
lz页面中jstl标签库的uri地址写的不正确。
[解决办法]
我这里使用的是jstl 1.1
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html