Question

I am getting below error.

FAIL - Application at context path /sampleJSF could not be started

I want to change my welcome file location. I have a index.jsp page at WEB-INF/pages/index.jsp. How can I modify servlet mapping and welcome file list to achive this?

Here is my servlet-mapping and welcome-file-list from web.xml.

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>WEB-INF/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>WEB-INF/pages/index.jsp</welcome-file>
</welcome-file-list>
Was it helpful?

Solution

It look like that you misunderstood the purpose of both the welcome file setting and the /WEB-INF folder.

The welcome file must represent the name of the file which the server should serve from the current folder when a folder is been requested instead of a file in URL. E.g. /, /foo/, /bar/, etc. So, when you set it to index.jsp, then it will serve /index.jsp when / is requested, and /foo/index.jsp when /foo/ is requested, etc.

The /WEB-INF folder is for files which shouldn't be independently publicly accessible. For example, include files, template files, error files, tag files, configuration files, etcetera. Mapping the Faces Servlet on /WEB-INF makes no utter sense as the servlet container already restricts direct (public) access to /WEB-INF folder when the enduser purposefully enters the /WEB-INF folder in the URL.

Undo all those changes you made on the sample web application. They make simply no sense. Whatever functional requirement you had in mind for which you incorrectly thought that this is the right solution must be solved differently.


Unrelated to the concrete problem, it look like that you're just getting started with JSF, but do you know that JSP is deprecated since JSF 2.0 in 2009? Are you absolutely positive that you're learning JSF based on the right and up to date resources? I strongly recommend to do so, or you will end up having confusion headache and code disaster. Start at our JSF wiki page.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top