1
  1. I created a test project based on Tomcat HelloWorld Servlet with Eclipse
  2. and tried to run it from Eclipse as is with Tomcat 7, which I have configured to run on 127.0.0.1 - but I get Page cannot be found at 127.0.0.1/helloworld/HelloWorld
  3. I also tried exporting as war file and deploying it to the (otherwise working) Tomcat server running as a Windows service - and deployed with the Tomcat Application Manager - manifest.mf and the classes are nicely copied to tomcat/webapps/helloworld, but trying to navigate to 127.0.0.1/helloworld/HelloWorld fails again, showing HTTP Status 404

From default @WebServlet to web.xml configuration

Next, in HelloWorld.java, I tried commenting out

//@WebServlet("/HelloWorld")

and then adding a web-application-specific web.xml configuration:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <servlet>
        <servlet-name>HelloWorld</servlet-name>
        <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorld</servlet-name>
        <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>
</web-app>

But the results are still the same - no response!

Solutions?

  • Given the linked tutorial provides instructions for Tomcat 6, should I change something to make it work with Tomcat 7?
  • Specifically, is the default @WebServlet("/HelloWorld") added by Eclipse sufficient? What is needed for the annotation-based configuration of Servlet 3.0 to work (without web.xml)?
  • Or could it be that something is blocking any web app deployment at the global tomcat server level? I have changed the server configuration somewhat, and unfortunately i do not remember exactly what, except for making it serve on 127.0.0.1 rather than 127.0.0.1:8080
Community
  • 1
  • 1
Cel
  • 6,467
  • 8
  • 75
  • 110
  • 1
    Add an index.html file in the root of the webapp. If you an hit this in your browser then the app is successfully deployed as the expected path and the problem is with the Servlet mapping. If not, then the app is not deployed at the expected path. – Alan Hay Jul 15 '12 at 11:45
  • @Alan Thanks!: I added /tomcat/webapps/helloworld/index.html but neither browsing to 127.0.0.1/helloworld/HelloWorld nor to 127.0.0.1/helloworld showed any new response - so seems like the latter i.e. the app is not deployed - how do i go on troubleshooting from here? – Cel Jul 15 '12 at 12:06
  • Don´t you have to specify the port, hence 127.0.0.1:8080/helloworld/HelloWorld? – wea Aug 08 '13 at 09:06
  • I'd been getting this problem: for some reason the tomcat setup on my deployment server ignores `@WebServlet` annotations, but if I redundantly add the information to web.xml then eclipse won't like it, so the solution is to remove the annotations and just use web.xml (I'm also using filters, so removing web.xml is not an option). – Jeremy List Apr 25 '14 at 05:18

2 Answers2

2

Open the properties page of your dynamic web project, click on "web project settings" and use the context root paramter as the root path for your URL.

Arne
  • 2,106
  • 12
  • 9
  • I am, I made it `helloworld` when i created the dynamic web project. However, it does seem that the crux of the issue is deployment of the app (and not the servlet) - for instance, after i deploy the war file with [the tomcat application manager](http://blog.techstacks.com/2009/05/tomcat-management-setting-up-tomcat.html), it does not appear in [the manager applications list](http://www.techstacks.com/.a/6a01156fbc6fe6970c0120a51c77e0970c-popup) even though it says `OK` to the deployment? – Cel Jul 15 '12 at 12:31
  • 1
    to see what really has been deployed by wtp, go to the debug configuration that defines how your server and web application is run, select arguments and look for the wtp.deploy jvm parameter. It defines the directory, where wtp has copied the files for your web application. Inspect that directory and see whether everything is where it should be and has the desired name. If something is missing, clean and republish (wtp is not very reliable on that deployment job). If the names are incorrect, check your projects configuration. – Arne Jul 15 '12 at 12:41
  • The main issue turned out to be that I was using Java 7 to compile the classes, so [changing the target to 1.6 resolved the issues](http://stackoverflow.com/questions/8982730/unsupportedclassversionerror-unsupported-major-minor-version-51-0-unable-to-load) – Cel Jul 15 '12 at 15:30
1

Try putting a default Index.html page in the WebContent and see if the welcome page points to it. If yes then try entering the servlet name manually and see if that works. I get the same error but doing so fixes it.

http://localhost:8080/<Project_Name>/index.html

http://localhost:8080/<Project_Name>/servlet_name