views:

317

answers:

5

I'm trying to create a simple web project using Tomcat in Java.

In the web.xml file, I point to a servlet that I want to be run when someone goes to http://localhost:8080/MyProject , so I used / as the URL pattern. That worked, however it has the disadvantage that all links to html and javascript files are being passed on to the main servlet instead of the appropriate file itself. Changing the Url pattern from / to /Home or /Main fixes it.

What am I doing wrong?

+1  A: 

Move your servlet to webapps/ROOT, as this is the default root context in Tomcat.

Alternatively, edit context.xml and set the root context path there.

Don Werve
A: 

You all its directory ROOT if it's unpacked or the war ROOT.war if it's packed.

nraynaud
+7  A: 

Why not use <welcome-file> attribute of web.xml.

Adeel Ansari
+1  A: 

you can setup a forward in the index.jsp at the root, and have it redirect to your servlet.

e.g., in your web.xml, you'd define your servlet mapping to some known path, such as "/home".

and in the your index.jsp at the root of your web-inf, you can write

<jsp:forward page="/home" />

check this for more info if you decide to take this route http://java.sun.com/products/jsp/tags/syntaxref.fm9.html

Chii
A: 

Get rid of the :8080 and the application name, and map the application anywhere by using Apache as the front-end, with ModJk communicating with the Tomcat server behind the scenes. After all, having to write :8080 is not like having a real homepage either, is it?

tucuxi