How to change the start page of my web project?

14,439

Solution 1

Try this servlet mapping:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

This works in Glassfish 3.

Solution 2

As far as I know always the index.jsp will be shown. You can add a redirect to the index.jsp:

<% response.sendRedirect("myStartPage.xhtml"); %>

But there might be a nicer solution.

Share:
14,439
javing
Author by

javing

Enthusiastic java developer based in London, I love stackoverflow, I use it regularly for many years and is a great way of helping and ask for help. Also i love blogging about software. Please visit my Blogs: Javing (Medium) Javing (Blogger)

Updated on June 04, 2022

Comments

  • javing
    javing almost 2 years

    When i created a new project in eclipse, it automatically created for me an index.jsp page, i don't want the start page to be a .jsp, i want it to be a .xhtml This is what i did at the web.xml:

    <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>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>myStartPage.xhtml</welcome-file>
    </welcome-file-list>
    </web-app> 
    

    The above code does not allow me to see the page myStartPage.xhtml as the first page when i run the project in localhost.

    How should i modify this for the browser to display for me the start page. Also i dont want to use any url-pattern. Is that mandatory?(I tried removing that tag, but it did not build).

    • jmj
      jmj almost 13 years
      Currently what does it show when you hit http://server:port/appContext/ ??
    • javing
      javing almost 13 years
      When i try: http://localhost:8080/projectname/ i get HTTP Status 500 javax.servlet.ServletException: The FacesServlet cannot have a url-pattern of /*.
  • javing
    javing almost 13 years
    I know i can redirect, but that is not what i need.
  • javing
    javing almost 13 years
    That is correct. Now i see that page as start page. But there is a little thing i don't understand: Why the URL, when i lauch just says : http://localhost:8080/projectname/ instead of http://localhost:8080/scarecrow1/myStartPage.xhtml ?
  • jmj
    jmj almost 13 years
    Because it forwards request internally and so the URL
  • McDowell
    McDowell almost 13 years
    @sfrj - see chapter 10.10 of the Servlet 3.0 spec for the most recent documentation on this.
  • javing
    javing almost 13 years
    Very useful .pdf, i rode the chapter 10.10 i understand now how welcome files work now. Thank you :)