How to set a servlet to run as the main page in Java?

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

In the web.xml file, I point to the servlet that I want to run when someone goes to http://localhost:8080/MyProject, so I used /the URL as a template. This worked, but the disadvantage is that all the links to the html and javascript files are passed to the main servlet, and not to the corresponding file. Changing the Url template from /to /Homeor /Maincorrects it.

What am I doing wrong?

+5
source share
5 answers

you can configure forward in index.jsp in the root directory and redirect it to your servlet.

, web.xml, , "/home".

index.jsp -inf

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

, http://java.sun.com/products/jsp/tags/syntaxref.fm9.html

+4
+10

webapps/ROOT, Tomcat.

context.xml .

+1

Get rid of the 8080 name and the application name and map the application anywhere using Apache as an interface, and ModJk communicates with the Tomcat server behind the scenes. In the end, you have to write: 8080 does not look like a real homepage, does it?

0
source

You all have its ROOT directory if it is unpacked or war ROOT.war if it is packed.

-2
source

All Articles