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?
Why not use <welcome-file>
attribute of web.xml.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With