0

I'm trying to let a welcome page displaying after running a dynamic web project. When googling I found a lot of tutorials but I can't found the solution. I share:

  • The structure of my project (I want that the page welcome.xhtml will displayed by default).
  • The file web.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
         id="WebApp_ID" 
         version="3.0">
 <display-name>HiSpring</display-name>
 <welcome-file-list>
  <welcome-file>welcome.xhtml</welcome-file>
 </welcome-file-list>
 
 <context-param>
  <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
  <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
  <param-value>client</param-value>
 </context-param>
 
 <context-param>
  <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
  <param-value>resources.application</param-value>
 </context-param>
 
 <listener>
  <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
 </listener>
 
 <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>/faces/*</url-pattern>
 </servlet-mapping>
</web-app>

Once clicking on HiSpring > Run As > Run on Server, I should have This url: http://localhost:8080/HiSpring/faces/welcome.xhtml. However, I got http://localhost:8080/HiSpring/.

Could you please tell me what I missed; Thanks in advance.

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Sofia
  • 19
  • 1
  • 7
  • What technology are you using? – kometen Sep 01 '16 at 20:59
  • Hello @kometen, I'm using the technology JEE6. – Sofia Sep 01 '16 at 21:03
  • Hi @Sofia, thank you. Please add them to the list in addition to welcome-file. Like java, servlets etc. – kometen Sep 01 '16 at 21:06
  • Hi @kometen, thanks a lot for your reply. If you don't mind, could you please give me an example?. – Sofia Sep 01 '16 at 21:15
  • I'm sorry I can't. I don't know what technology you are using. Before asking you must supply adequate information before people can help you. Such as webserver, language etc. – kometen Sep 01 '16 at 21:25
  • Excuse me Sir for this ambiguity:The web server is Tomcat 7.0. The language is Java. The frameworks are: JSF 2.2, Spring 4.0.2. – Sofia Sep 01 '16 at 21:31
  • Awesome. Hope your issue will be solved, I don't know much though about spring nor JSF. – kometen Sep 01 '16 at 21:40
  • Some small things: On Tomcat7 using Spring, you are **not** running JEE6!. And JSF2.2 is not a framework, it is an api spec. Mojarra 2.2.x or MyFaces 2.2.x are the 'frameworks' – Kukeltje Sep 02 '16 at 07:14

1 Answers1

0

According to your web.xml tomcat would look for /welcome.xhtml and has no clue that this might be in /faces/welcome.xhtml. The URL is fine (if welcome.xhtml is in /)

There might be a more elegant JSF version (I'm not much of a JSF guy) - some possible solutions that come to my mind would be

  • map the faces servlet to *.xhtml do remove the /faces/ part from path (you judge if this is proper JSF - comment if it's not and I'll remove this part)
  • create a separate explicit redirection, e.g. through a (stupidly simple) index.html (of course, declare index.html as another welcome file) like the following sample:
<html>
 <head><title>Redirection</title>
  <meta http-equiv="refresh" content="2;URL=/faces/">
  <!-- 2 means 2 seconds delay. Change as you like -->
 </head>
 <body>
  <p>redirecting to application. <a href="/faces/">Click here if it doesn't work</a></p>
 </body>
</html>
Olaf Kock
  • 46,930
  • 8
  • 59
  • 90