0
votes

I have this folder directory:

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

I have this 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 has this 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() + "'");
}

When I start Tomcat, this the output (init loads and it finds the class).

enter image description here

However, when I go to localhost:8080/LoginServlet it says resource not found. Been struggling for days. Any help is appreciated!

2
Is it possible that something is screwy in the tomcat config, and it's binding the ROOT context to some other path? - Ian McMahon
What does the LoginServlet do? - Ryan Stewart
@RyanStewart, handles logins. Has protected void processRequest(HttpServletRequest request, HttpServletResponse response) function. - jn1kk
@IanMcMahon, default config. - jn1kk
It matters because when you request it, you get an error. The problem could be in the servlet. The full error message could shed some light, too. - Ryan Stewart

2 Answers

3
votes

You need to add

<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>

and remove <url-pattern> from the place where you have.

1
votes

Fixed with the following (WTF Tomcat).

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

  <servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>com.mycompany.server.LoginServlet</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
</web-app>