Search code examples
javajspglassfishwelcome-file

Glassfish server welcome-file not working?


I have a very simple web.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <welcome-file-list>
        <welcome-file>abcd.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>foo</param-name>
        <param-value>bar</param-value>
    </context-param>
</web-app>

and I have 2 jsp files hello.jsp and abcd.jsp in my application.

I deployed the war file to Glassfish Server, context root is "novone"

When I go to localhost:8080/novone I see hello.jsp, not abcd.jsp...

In Glassfish admin panel(local4848/common/index.jsf) Applications->novone->Descriptor->Description-File I see:

<?xml version="1.0" encoding="UTF-8" ?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <welcome-file-list>
        <welcome-file>abcd.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>foo</param-name>
        <param-value>bar</param-value>
    </context-param>
</web-app> 

How come hello.jsp is served and not abcd.jsp?

When I manually go to /novone/abcd.jsp I can see the value "bar" which is loaded from the application scope.


Solution

  • This wasn't obvious, but I found that if you are having IntelliJ autogen the war file, if you go into Project Structure > Facets, you will see under Web that there is one Web Module Deployment Descriptor in the top right box, and one Web Resource Directory in the bottom right box.

    If you highlight that web resource directory in the bottom frame you will see that the Web Resource Directory is probably set to /web by default as the root.

    You can hit the Edit icon and update this to the / then your welcome file should work, as it will then be considered within your web resources.