0

Although I am proficient in Java, I am completely new to developing web apps with maven and I am struggling to get started by creating a simple HelloWorld servlet app - I'm using Eclipse Mars and Tomcat 8.

I have added a simple servlet which should print out "hello world" but when I attempt to run the servlet by using the url-pattern (so http://localhost:8080/MyApp/HelloWorld) I get a 404 error.

When I ran the app for the very first time I got a 500 error stating that my servlet class could not be found but when I refreshed the page it changed to 404. Now I only get a 404 error. I have already tried the following but no joy - TOMCAT - HTTP Status 404.

Any help would be much appreciated.

Servlet class and web.xml

Community
  • 1
  • 1
N Robinson
  • 11
  • 2
  • Have you read Tomcat's startup log from top to bottom? Clues are usually found there (in Eclipse it's just there in *Console* tab). Warnings/Errors/Exceptions are usually quite googlable if not already self-explaining. – BalusC Feb 28 '16 at 22:00
  • You have your java sources located in src/main/resources which is not the right place for this. Please create a directory src/main/java and put them there. This may remedy your problem. – Torsten Feb 28 '16 at 22:08
  • Eureka! I have only spent the last 4 hours trying to fix this, I knew it would be something simple! Thanks for the help, you're a life saver! – N Robinson Feb 28 '16 at 22:14
  • Added the content as an answer. – Torsten Feb 28 '16 at 22:29
  • That should have thrown a `ClassNotFoundException` on the servlet class in the server log which is in turn fairly self-explaining (the servlet class cannot be found). This in turn suggests you didn't bother to read the server log. In the future, do so. It's a source of clues. – BalusC Feb 29 '16 at 09:38
  • Chill. It did throw a class not found exception as I have stated in my original post. I thought the problem was due to the file structure and location of my servlet which is why I included an image of the directory structure in my post. When you add a servlet in Eclipse, it puts them in a resources folder by default. I tried moving the servlet class around but I couldn't find an example of the correct way to structure the app on the net. – N Robinson Feb 29 '16 at 11:17

1 Answers1

0

You have your java sources located in src/main/resources which is not the right place for this. Please create a directory src/main/java and put them there. This should remedy your problem.

Torsten
  • 6,184
  • 1
  • 34
  • 31