Java @webServlet不能与tomcat 7 eclipse一起使用
我正在用ApacheTomcat7构建一个将文件上传到服务器的基本应用程序 但是,每当我在tomcat和webServlet上使用apachecommons文件上传时,它都不会启动Java @webServlet不能与tomcat 7 eclipse一起使用,java,eclipse,servlets,tomcat7,apache-commons-fileupload,Java,Eclipse,Servlets,Tomcat7,Apache Commons Fileupload,我正在用ApacheTomcat7构建一个将文件上传到服务器的基本应用程序 但是,每当我在tomcat和webServlet上使用apachecommons文件上传时,它都不会启动 @WebServlet("/test123") public class TestServlet extends HttpServlet {.... <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.o
@WebServlet("/test123")
public class TestServlet extends HttpServlet {....
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test_new</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test123</url-pattern>
</servlet-mapping>
</web-app>
但是当我删除@webServlet('/link url')
时,应用程序会启动,但无法在该url上找到资源
public class TestServlet extends HttpServlet {...
即使我在web.xml中添加上述链接,应用程序也不会启动
@WebServlet("/test123")
public class TestServlet extends HttpServlet {....
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>test_new</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test123</url-pattern>
</servlet-mapping>
</web-app>
有人能帮忙吗?这显然是一个
ClassNotFoundException
,如图所示
Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory
应用程序类路径中缺少
commons fileupload.jar
。查找、下载并将该jar
放入应用程序的/WEB-INF/lib
文件夹中,然后重新启动。您如何尝试访问url?另外,应用程序的上下文路径是什么?使用一个表单,尝试转到localhost:8080/yourapp/test123
,以获得注释示例的乐趣。我在上面编写了它。它说找不到资源404。在注释示例中,服务器未启动,因此无法连接到localhost:8080。如果服务器未启动,请显示错误日志。谢谢。。它起作用了。。但我所做的是在构建配置中添加commons fileupload jar。如果你在Eclipse上,有时可能会发生它的类路径与Tomcat的应用程序启动器不同步的情况。