84

I was following the tutorial on o7planning and got stuck at step 6:

http://o7planning.org/en/10169/java-servlet-tutorial

It's just a simple project that show HelloWorld but for some reason I keep getting 404 error. Detail:

enter image description here However the Tomcat welcome page showing properly.

Tomcat welcome page

Here solutions that I've tried so far (and they are NOT working):

Right-click project -> properties -> Project Facets -> Runtimes -> checked "Apache Tomcat v9.0" -> Apply -> finish.

Server tab -> Right-click "Tomcat v9.0..." -> properties -> switch location -> Choose "Use tomcat installation" on "Server locations" panel.

Community
  • 1
  • 1
Lê Quang Bảo
  • 2,670
  • 2
  • 27
  • 40

2 Answers2

54

Problem solved, I've not added the index.html. Which is point out in the web.xml

enter image description here

Note: a project may have more than one web.xml file.

if there are another web.xml in

src/main/webapp/WEB-INF

Then you might need to add another index (this time index.jsp) to

src/main/webapp/WEB-INF/pages/

Lê Quang Bảo
  • 2,670
  • 2
  • 27
  • 40
  • 14
    What is the content of it? – Eftekhari Apr 14 '17 at 23:29
  • 5
    what is your web.xml look like? – Suresh Aug 06 '18 at 13:10
  • 1
    @mannedear It's just the default auto-generated web.xml, I didn't change anything. If you have strictly followed the tutorial on o7planning (see the url in the question) then you should get the same file as mine. – Lê Quang Bảo Aug 07 '18 at 04:14
  • hi @LêQuangBảo where yo added index.html file – Karthiga Jan 09 '19 at 07:31
  • 1
    Hi @Karthiga, it in WebContent folder. If you don't know where the folder is, just take a look at the image in my answer. – Lê Quang Bảo Jan 09 '19 at 09:36
  • 1
    yeah thanks @LêQuangBảo. But while i run this url 'http://localhost:8081/ServletTutorial/hello' i got an error " Error instantiating servlet class [org.o7planning.tutorial.servlet.HelloServlet]" Do you know what it is – Karthiga Jan 09 '19 at 09:39
  • Sorry @Karthiga, I don't want to deal with servlet anymore so I've switched to Spring boot for a long time. Good luck Googling. – Lê Quang Bảo Jan 09 '19 at 09:43
  • This worked for me too, thanks – jned29 Aug 22 '19 at 05:55
  • @Karthiga I got the above 404 error while doing localhost:8080/ServletDemo/ServletDemo, so, I figured out that I need to build my project in Eclipse in order to get the ".class" file of the servlet.java. And automatic build was not set. So, I first build the project and then run it, and it worked for me. – Deepam Gupta Nov 22 '19 at 10:52
  • This solution does't work for me, but I found this that solves, hope help anyone else. https://stackoverflow.com/questions/43590008/the-origin-server-did-not-find-a-current-representation-for-the-target-resource/48578205#48578205 – rfonte Sep 12 '20 at 16:03
  • In my case, I had removed/deleted the ROOT.war from tomcat/webapps. After putting it back, it worked. – Sanket Mehta May 04 '21 at 10:14
22

From Eclipse, you right-click the project -> Run As -> Run on Server. It worked for me. I used Eclipse Jee Neon and Apache Tomcat 9.0.

I just removed the head portion in index.html file and it worked fine. This is the head tag in HTML file:
This is the head tag in html file

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • you removed the head from your html and it worked fine after yeah? this makes me not like tomcat. i will vote yours mind as it sounds simpler. – Tomachi Apr 11 '21 at 14:00
  • In my case, I had removed/deleted the ROOT.war from tomcat/webapps. After putting it back, it worked. – Sanket Mehta May 04 '21 at 10:14
  • There was same problem with another webapp (war file). During app server startup, may be it was not exploded/extracted correctly so It's web.xml was missing. I copied the original webapp.war file and let tomcat explode it again. web.xml can be seen now. And the problem is solved. – Sanket Mehta May 10 '21 at 07:55
  • yah! Actually when we make any changes in the XML file then we need to restart the server. so not just eclipse, it will work with every IDE. – Brijal Kansara Jun 07 '22 at 12:57