Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a Servlet to run as the Homepage in Java? [duplicate]

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?

like image 909
Ali Avatar asked Apr 03 '09 00:04

Ali


2 Answers

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

like image 193
Adeel Ansari Avatar answered Nov 15 '22 04:11

Adeel Ansari


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

like image 43
Chii Avatar answered Nov 15 '22 04:11

Chii