我有这个文件夹目录:
webapps/ROOT/META-INF/
......................上下文.xml
webapps/ROOT/WEB-INF/
......................web.xml
webapps/ROOT/WEB-INF/lib
.........................mysql-connector-java-5.1.23-bin.jar
webapps/ROOT/WEB-INF/classes/com/mycompany/server/LoginServlet.class
我有这个 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
<servlet-class>com.mycompany.server.LoginServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
LoginServlet.java 有这个init()
@Override
public void init(ServletConfig config) throws ServletException {
System.out.println("Login Servlet Is Running");
new Thread(guestRouter).start();
System.out.println("path: '" + config.getServletName() + "'");
}
当我启动 Tomcat 时,这是输出(init 加载并找到类)。
但是,当我去localhost:8080/LoginServlet
它说找不到资源。这几天一直在挣扎。任何帮助表示赞赏!