【发布时间】:2013-02-11 11:08:19
【问题描述】:
我有这个文件夹目录:
webapps/ROOT/META-INF/
......................context.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 时,它说找不到资源。这几天一直在挣扎。任何帮助表示赞赏!
【问题讨论】:
-
是否有可能是在 tomcat 配置中有问题,并且它正在将 ROOT 上下文绑定到其他路径?
-
LoginServlet 是做什么的?
-
@RyanStewart,处理登录。具有
protected void processRequest(HttpServletRequest request, HttpServletResponse response)功能。 -
@IanMcMahon,默认配置。
-
这很重要,因为当您请求它时,您会收到错误消息。问题可能出在 servlet 中。完整的错误消息也可以提供一些启示。