1

I have a Tomcat server running with index.jsp but when I add the .class servlet it turns the index.jsp into Not found 404.

This is my web.xml in /opt/tomcat9/webapps/ROOT/WEB-INF

// Servlets
<servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>com.tyd.gr1.la.login</servlet-class>
</servlet>

// Servlet Mappings
<servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>

My index.jsp is located in /opt/tomcat9/webapps/ROOT

If I remove the login.class in /opt/tomcat9/webapps/ROOT/WEB-INF/classes/com/tyd/gr1/la and start tomcat I get presented with the index.jsp

But if I put login.class back I get HTTP Status 404 – Not Found Type Status Report

Message Not found

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Screenshot1

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • why are you trying to install into the `ROOT` webapp? – Scary Wombat Nov 27 '18 at 00:30
  • `WEB-INF` is supposed to be placed directly under `webapp` – Ramanlfc Nov 27 '18 at 00:32
  • I found the "Tomcat is properly configured" index.html there so I replaced it with my own index.jsp. It shows but when I add a java .class suddenly I get 404 – wingchun1274 Nov 27 '18 at 00:34
  • @wingchun1274 please post a proper screen shot of your directory structure and also what url you are entering – Ramanlfc Nov 27 '18 at 00:37
  • @wingchun1274 what method have you mapped inside your login.java class to handle '/' path ? – AppleCiderGuy Nov 27 '18 at 00:45
  • @Ramanlfc I have posted the Screenshot in Screenshot1 – wingchun1274 Nov 27 '18 at 00:46
  • are you really just pasting in a .class file ??? – AppleCiderGuy Nov 27 '18 at 00:46
  • @Harshal On my Windows PC I made a .java that uses the data from a form in the index.jsp to check against a database. In IntelliJ IDE the .java works with the index.jsp. I used javac and the neccesary libraries on my pi to compile the .java into .class so I can put it in Tomcat. – wingchun1274 Nov 27 '18 at 00:49
  • @Ramanlfc After I moved `WEB-INF` under `webapps`. Tomcat doesn't make a link to the `login.class` anymore. In my `index.jsp` it is `
    `. Now after I press submit it gives an `error 404 for /login`
    – wingchun1274 Nov 27 '18 at 00:59

1 Answers1

0

I have just been fighting this. Some things that helped me:

  • check your web.xml has correct spelling of tags such as <servlet>

  • check your naming in <servlet-class></servlet-class>

    i.e. <servlet-class>com.tyd.gr1.la.login</servlet-class>

  • build as a war and let Tomcat deploy. It will likely use: webapps/WEB-INF/classes/com/tyd/gr1/la note the ROOT is dropped

  • note case sensitivity. For me in one example

    <form action=\"HelloWorld\" method=\"POST\">\r\n") - BROKE giving a 404

    <form action=\"helloworld\" method=\"POST\">\r\n") - worked

  • If you are still struggling start to comment out your xml.web declarations to isolate what is breaking. I found I could reach assets and HTML pages, JSPs and other elements until I finally fixed the class naming and it all worked.

SlinnShady
  • 435
  • 4
  • 10
  • This was a long time ago, I think I avoided this by deploying it via a .war file instead of manually putting it in directories. – wingchun1274 Oct 17 '20 at 15:03