Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Sevlet Mapping. Welcome File List

Tags:

java

web.xml

In my web.xml file I have this

<!-- WELCOME FILE LIST -->
<welcome-file-list>
    <welcome-file>/index</welcome-file>
</welcome-file-list>

Which maps to this

<!-- SERVLET FOR THE HOME PAGE -->
<servlet>
    <servlet-name>HomePageServlet</servlet-name>
    <servlet-class>com.gmustudent.HomePageServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>HomePageServlet</servlet-name>
    <url-pattern>/index</url-pattern>
</servlet-mapping>

When I put this in the address bar I get my home page site and the servlet grabs all of my content as requested.

http://localhost:8086/gmustudent/index

However, this gives me a 404

http://localhost:8086/gmustudent/

Why isn't my welcome file list grabbing that welcome file servlet when index is not explicitly stated?

like image 900
gmustudent Avatar asked Nov 04 '12 19:11

gmustudent


People also ask

What is a welcome file list?

The welcome files mechanism allows you to specify a list of files that the web container will use for appending to a request for a URL (called a valid partial request) that is not mapped to a web component.

Which file contains servlet mapping?

Java web applications use a deployment descriptor file to determine how URLs map to servlets, which URLs require authentication, and other information. This file is named web. xml , and resides in the app's WAR under the WEB-INF/ directory.

In which folder we can put web xml?

The deployment descriptor is a file named web. xml . It resides in the app's WAR under the WEB-INF/ directory.

What is load on startup in servlet?

The load-on-startup element of web-app loads the servlet at the time of deployment or server start if value is positive. It is also known as pre initialization of servlet. You can pass positive and negative value for the servlet.


1 Answers

     http://localhost:8086/gmustudent/

gmustudent is the context root of your webapplication. index is the resource you wanna access.

you configure welcome file like below, remove the prepending / :

<welcome-file>Index</welcome-file> 
</welcome-file-list> 

to access

  http://localhost:8086/gmustudent/
like image 102
PermGenError Avatar answered Sep 21 '22 04:09

PermGenError