naddnan
naddnan

Reputation: 161

eclipse dynamic web project default start page

I created an eclipse dynamic web project, with home.jsp in the WEB-INF folder

The server I'm using is Tomcat 7.0.35

The name of the project is Pilot_1, and I have a servlet which triggers when the URL-pattern is /home

@WebServlet(description = "Initalizes the table", urlPatterns = { "/home" })

I want to specify the URL so that everytime I press Project > Run > Run on Server, the URL is specifically localhost:8080/Pilot_1/home (triggering both the servlet and the jsp page).

I tried changing the Context Root to only "Pilot_1", which gives the URL "localhost:8080/Pilot_1" and doesn't trigger the servlet

I tried changing the Context Root to "Pilot_1/home", which gives the URL "localhost:8080/Pilot/1/home/" and the extra '/' ensures that the servlet doesn't trigger

I tried changing the Context Root to to "home", which gives the URL "localhost:8080/home/", and again, the extra '/' ensures that the servlet doesn't trigger

I've been playing around with URLs and it seems the only time the servlet gets triggered is when the URL is "localhost:8080/Pilot_1/home"

Is there any workaround to this?

This is my web.xml

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>home.jsp</welcome-file>

Upvotes: 1

Views: 9538

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

Don't mess with the Context root. Instead, go to the web.xml file and change the welcome-file-list:

<welcome-file-list>
    <!-- note that THIS IS NOT home.jsp, just home (the URL mapping of your servlet) -->
    <welcome-file>home</welcome-file>
</welcome-file-list>

By the way, revert any change you have done to the context root of the application.

Refer to this answer for an example.

Upvotes: 4

Related Questions