1

I am trying to get Tomcat to work in eclipse but it simply refuses to. I have followed this and this tutorial. But it keeps displaying the page below despite my efforts.It says that server is started succesfully in eclipse. But I am unable to access localhost:8080 in my browser. THe server works perfectly fine if I manually start it from the start menu. However when I try to run an application from eclipse it does not work. Could someone please help me out?

enter image description here

enter image description here

user1179510
  • 1,003
  • 1
  • 14
  • 24

4 Answers4

3

You seem to want to access your web project on the domain root instead of on the web project's default context root which defaults to the Eclipse project name. If your Eclipse project name is for example "myproject" then it would be available on http://localhost:8080/myproject and the FirstServlet would be available on http://localhost:8080/myproject/FirstServlet.

If you need to access the web project on the domain root, then you should change the web project's context root to /. You can do that in the Web Project Settings entry of the web project's properties which you can access by rightclicking the project and choosing Properties.

enter image description here

Please note that those Tomcat-specific 404 errors are an indication that Tomcat runs perfectly fine. If Tomcat didn't run, then you would have gotten a webbrowser-specific "Connection timeout" error page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • After reading your answer I tried changing it to /. However the project still does not show up after setting it to / .I am still unable to access the servlet. The project name is secondservlet and servlet name is the same too. I entered localhost:8080/secondservlet with the project properties set to root. It still does not work – user1179510 Jul 04 '12 at 12:25
  • That is a different problem. Read the server logs for any errors. If there are none, then the servlet has simply not been registered at all. For some proper and complete Hello World examples, read our Servlets wiki page: http://stackoverflow.com/tags/servlets/info – BalusC Jul 04 '12 at 12:27
  • It still says HTTP Status 404 - /SecondServlet/. I realized why localhost:8080 worked. I added the root as an external module according to @Shiv Kumar Ganesh. When I removed it it stopped working – user1179510 Jul 04 '12 at 12:29
  • As said, read the server logs for any errors. If there are none, then the servlet has simply not been registered at all. For some proper and complete Hello World examples, read our Servlets wiki page: http://stackoverflow.com/tags/servlets/info Edit: I have checked the two tutorial links in your question, the first one is okay, the second one is bad and misleading. You would by default not get the Tomcat default homepage in Eclipse at all. The author don't know what he is talking about. Related: http://stackoverflow.com/questions/2280064 – BalusC Jul 04 '12 at 12:34
  • Will read the hello world tutorials again. I agree that it does not show that page by default unless you set the modules in eclipse.- That was pretty confusing! – user1179510 Jul 04 '12 at 12:41
  • I have no such and option – IntoTheDeep Apr 09 '16 at 16:15
0

I have a solution for you . I guess you have configured Tomcat on Eclipse. Then click on server tab and then double click on server (as in tomcat server). A tomcat configuration page opens up. Now look at the bottom left corner of the page you would find a tab named modules. click on it. Click--->Add Module-->Navigate to Tomcats WepApp folder---> "Your Deployment Folder"

enter image description here

enter image description here

The above image shows How I navigated from Add External we Module and added the ROOT folder to my web module. Remember I added the server in eclipse. I hope you did the same.

Shiv Kumar Ganesh
  • 3,799
  • 10
  • 46
  • 85
  • There is a web module and an external web module. Which should I choose. Also should I add the exact webapp directory for tomcat like D:\Tomcat\WebApp becuase my current eclipse work space is differnet from the place where tomcat webapps are present – user1179510 Jul 04 '12 at 10:41
  • For me it was root so I clicked on Add External Web Module and navigated to the Root Folder inside my webapps. I have updated the answer with Images. – Shiv Kumar Ganesh Jul 04 '12 at 11:13
  • localhost:8080 works if i do this. But the servlet I am writing still does not get displayed as I am in a different workspace altogether. – user1179510 Jul 04 '12 at 12:32
  • Then Change the Workspace :) and try again – Shiv Kumar Ganesh Jul 04 '12 at 13:09
0

you need use localhost:8080/{project-name}/FirstServlet or set the context root to / from eclipse settings to be able to access it like localhost:8080/FirstServlet

fmucar
  • 14,361
  • 2
  • 45
  • 50
0

thanks it really helped . adding the web module(ROOT) in eclipse helped Navugate to Add External web Module and added the ROOT folder to my web module.

copy the ROOT folder from TOMCAT_HOME/webapps/ROOT