老师,您好!我将操作Java Web开发实战1200例(第1卷)的182例部署好后,启动Tomcat时,就报java.lang.NoClassDefFoundError:org/apache/commons/logging/logFactory
at com.mr.LogFiter.<init>(LogFiter.java:18),我已经加入了org-apache-commons-logging.jar和 log4j-1.2.14jar两个包,但还是报错,请老师有空帮看一下,十分感谢!
老师,您好!
第18行代码:private Log log = LogFactory.getLog(this.getClass());
以下是所有的:
package com.mr;
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;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LogFilter implements Filter {
private Log log = LogFactory.getLog(this.getClass());
private String filterName;
public void init(FilterConfig config) throws ServletException {
filterName = config.getFilterName();//获取 Filter的 name,启动Filter
log.info("启动 Filter: " + filterName);//
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
long startTime = System.currentTimeMillis();//运行前的时间
String requestURI = request.getRequestURI();//获取访问的URI
requestURI = request.getQueryString() == null ? requestURI//所有的地址栏参数对比
: (requestURI + "?" + request.getQueryString());
chain.doFilter(request, response);
long endTime = System.currentTimeMillis();
//消耗的总时间
log.info(request.getRemoteAddr() + " 访问了 " + requestURI + ", 总用时 "
+ (endTime - startTime) + " 毫秒。");
}
public void destroy() { //销毁时记录日志
}
}
jzy81208 发表于2017-06-19 14:22
老师,您好!
第18行代码:private Log log = LogFactory.getLog(this.getClass());
以下是所有的:
package com.mr;
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;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class LogFilter implements Filter {
private Log log = LogFactory.getLog(this.getClass());
private String filterName;
public void init(FilterConfig config) throws ServletException {
filterName = config.getFilterName();//获取 Filter的 name,启动Filter
log.info("启动 Filter: " + filterName);//
}
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
long startTime = System.currentTimeMillis();//运行前的时间
String requestURI = request.getRequestURI();//获取访问的URI
requestURI = request.getQueryString() == null ? requestURI//所有的地址栏参数对比
: (requestURI + "?" + request.getQueryString());
chain.doFilter(request, response);
long endTime = System.currentTimeMillis();
//消耗的总时间
log.info(request.getRemoteAddr() + " 访问了 " + requestURI + ", 总用时 "
+ (endTime - startTime) + " 毫秒。");
}
public void destroy() { //销毁时记录日志
}
}
你好:
sorry啊~最近有些忙,没看到你回复的,看你上述代码,看来还是包错误。给你传个这个commons-logging-1.1.1.jar,看看是否可用。
老师,早,昨天的两个包打上去,还是报错啊,后来我网上下载了commons-fileupload-1.3.2.jar包打上去,也报错啊,提示找不到类DiskFileUpload,请老师百忙中帮看一下,十分感谢!具体提示如下:
java.lang.ClassNotFoundException: org.apache.commons.fileupload.DiskFileUpload
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at com.count.Online.UploadRw.<init>(UploadRw.java:37)
at com.count.Online.UploadFilter.doFilter(UploadFilter.java:20)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
jzy81208 发表于2017-06-23 08:46
老师,早,昨天的两个包打上去,还是报错啊,后来我网上下载了commons-fileupload-1.3.2.jar包打上去,也报错啊,提示找不到类DiskFileUpload,请老师百忙中帮看一下,十分感谢!具体提示如下:
java.lang.ClassNotFoundException: org.apache.commons.fileupload.DiskFileUpload
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at com.count.Online.UploadRw.<init>(UploadRw.java:37)
at com.count.Online.UploadFilter.doFilter(UploadFilter.java:20)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
你好:
可能由于版本过高引起的,试着找commons-fileupload-1.0.jar 这个版本。