masterial
masterial

Reputation: 2216

How do I set up deployment descriptor in GlassFish in order to run servlet in place of welcome page?

I am runing a GlassFish Server Open Source Edition 3 (Java EE 6). I am having a difficulty trying to set up the descriptor file "sun-web.xml" for deployment of my web application. I want to bring up a servlet as the welcome page instead of traditional "index.jsp" when I open http://localhost:8080/MyWebApplication/.

Can someone help?

Upvotes: 1

Views: 2518

Answers (2)

Rajesh Pantula
Rajesh Pantula

Reputation: 10241

Change the deployment descriptor of your web-app and change the welcome-file list to point your servlet.

<!– ==Default Welcome File List========== –>


When a request URI refers to a directory, the default servlet looks for a “welcome file” within that directory and, if present, to the corresponding resource URI for display. If no welcome file is present, the default servlet either serves a directory listing, or returns a 404 status, depending on how it is configured.
If you define welcome files in your own application’s web.xml deployment descriptor, that list *replaces* the list configured here, so be sure that you include any of the default values that you wish to include.



<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

change the above lines to point to the servlet path of your servlet.

/MyServlet

</welcome-file-list>

Be carefule to give the same-path of your servlet as specified in servlet url-mapping

Upvotes: 0

masterial
masterial

Reputation: 2216

I had to create the web.xml file in WebContent/WEB-INF/ folder.

<?xml version="1.0" encoding="UTF-8"?>   
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">   
    <servlet>   
        <servlet-name>Index</servlet-name>   
        <servlet-class>server.Index</servlet-class>   
    </servlet>   
    <servlet-mapping>   
        <servlet-name>Index</servlet-name>   
        <url-pattern>/Index</url-pattern>   
    </servlet-mapping>   
    <welcome-file-list>   
        <welcome-file>Index</welcome-file>   
        </welcome-file-list>   
    <session-config>   
        <session-timeout>   
            30  
        </session-timeout>   
    </session-config>   
</web-app> 

Upvotes: 2

Related Questions