org.apache.jasper.JasperException: Unable to load class for JSP
at org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:599)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:141)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at cn.com.ReducePageFilter.doFilter(ReducePageFilter.java:54)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at cn.com.CharsetFilter.doFilter(CharsetFilter.java:27)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:595)

ReducePageFilter.java 54句
chain.doFilter(request, wrapper);
CharsetFilter.java 27句
_chain.doFilter(_req, _res);
public class ReducePageFilter implements Filter { public void init(FilterConfig filterConfig) throws ServletException {
} public void destroy() {
} public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; String transferEncoding = getGZIPEncoding((HttpServletRequest) request); if (transferEncoding == null) {
chain.doFilter(request, response);
} else {
ReduceWrapper wrapper = new ReduceWrapper(resp);
chain.doFilter(request, wrapper);
byte[] gzipData = gzip(wrapper.getResponseData());
resp.addHeader("Content-Encoding", "gzip"); resp.setContentLength(gzipData.length);
ServletOutputStream output = response.getOutputStream();
output.write(gzipData);
output.flush();
}
} private String getGZIPEncoding(HttpServletRequest request) {
String acceptEncoding = request.getHeader("Accept-Encoding");
if (acceptEncoding == null) {
return null;
}
acceptEncoding = acceptEncoding.toLowerCase();
if (acceptEncoding.indexOf("x-gzip") >= 0) {
return "x-gzip";
}
if (acceptEncoding.indexOf("gzip") >= 0) {
return "gzip";
}
return null;
} private byte[] gzip(byte[] data) {
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream(10240);
GZIPOutputStream output = null;
try {
output = new GZIPOutputStream(byteOutput);
output.write(data);
} catch (IOException ex) {

WriteLog.writeLog(4, "ReducePageFilter", "gzip",
Config.LogCommand, Config.LogCommand, ex.getMessage());
ex.printStackTrace();

} finally {
if (output != null) {
try {
output.close();
} catch (IOException ex) {
WriteLog.writeLog(4, "ReducePageFilter", "gzip",
Config.LogCommand, Config.LogCommand, ex.getMessage());
ex.printStackTrace();
}
}
}
return byteOutput.toByteArray();
}
}class ReduceWrapper extends HttpServletResponseWrapper { public static final int OT_NONE = 0, OT_WRITER = 1, OT_STREAM = 2; private int outputType = OT_NONE; private ServletOutputStream output = null; private PrintWriter writer = null; private ByteArrayOutputStream buffer = null; public ReduceWrapper(HttpServletResponse resp) throws IOException {
super(resp);
buffer = new ByteArrayOutputStream();
} public PrintWriter getWriter() throws IOException {
if (outputType == OT_STREAM)
throw new IllegalStateException();
else if (outputType == OT_WRITER)
return writer;
else {
outputType = OT_WRITER;
writer = new PrintWriter(new OutputStreamWriter(buffer,
getCharacterEncoding()));
return writer;
}
} public ServletOutputStream getOutputStream() throws IOException {
if (outputType == OT_WRITER)
throw new IllegalStateException();
else if (outputType == OT_STREAM)
return output;
else {
outputType = OT_STREAM;
output = new WrappedOutputStream(buffer);
return output;
}
} public void flushBuffer() throws IOException {
if (outputType == OT_WRITER)
writer.flush();
if (outputType == OT_STREAM)
output.flush();
} public void reset() {
outputType = OT_NONE;
buffer.reset();
} public byte[] getResponseData() throws IOException {
flushBuffer();
return buffer.toByteArray();
} class WrappedOutputStream extends ServletOutputStream { private ByteArrayOutputStream buffer; public WrappedOutputStream(ByteArrayOutputStream buffer) {
this.buffer = buffer;
} public void write(int b) throws IOException {
buffer.write(b);
} public byte[] toByteArray() {
return buffer.toByteArray();
}
}}
public class CharsetFilter implements Filter { private FilterConfig cfg = null; public void init(FilterConfig fcfg) {
this.cfg = fcfg;
} public void doFilter(ServletRequest _req, ServletResponse _res,
FilterChain _chain) {
WriteLog.writeLog(1, "CharsetFilter", "doFilter", Config.LogCommand,
Config.LogCommand, Config.LOGSTART);
try { String _enc = this.cfg.getInitParameter("encode");
if ((_enc == null) || !(_enc.equals(""))) {
_enc = "GBK";
}
WriteLog.writeLog(3, "CharsetFilter", "doFilter", Config.LogCommand,
Config.LogCommand, _enc);
_req.setCharacterEncoding(_enc);
_res.setContentType("text/html;charset=" + _enc);
_chain.doFilter(_req, _res);
} catch (Exception ex) {
WriteLog.writeLog(4, "CharsetFilter", "doFilter",
Config.LogCommand, Config.LogCommand, "error:"
+ ex.getMessage());
ex.printStackTrace();
}
WriteLog.writeLog(1, "CharsetFilter", "doFilter", Config.LogCommand,
Config.LogCommand, Config.LOGEND);
} public void destroy() {
}}

解决方案 »

  1.   

    你是不是自己实现了GZIP压缩啊!?我用tomcat,他自己就支持gzip压缩,我想其他的应用服务器也都应该支持,所以.....建议你用他们的算了。
      

  2.   

    org.apache.jasper.JasperException:   Unable   to   load   class   for   JSP 看样子lz应该错在没有在jsp里import对应的class或者引入的不正确~
    还有一个可能的原因是lib引入的不全,jsp-api.jar和servlet-api.jar都要引入~