Question

I am try to make a my first jsf2 project run on jboss7.1 I want to redirect from the index.jsp to map.xhtml that's what I try in my index.jsp and all of them didn't work please help

<%=response.sendRedirect("map.html")  %>
<%=response.sendRedirect("/map.html")  %>
<%=response.sendRedirect("map.xhtml")  %>
<%=response.sendRedirect("/map.xhtml")  %>
<%=response.sendRedirect("map.jsf")  %>
<%=response.sendRedirect("/map.jsf")  %>

and this is my faces-config.xml

<faces-config
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-facesconfig_2_1.xsd"
version="2.1">

</faces-config>

this is my web.xml

<?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_2_5.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>myproject</display-name>
  <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>*.jsf</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>
Was it helpful?

Solution

Don't do it the hard way.

Change

<url-pattern>*.jsf</url-pattern>

to

<url-pattern>*.xhtml</url-pattern>

and change

<welcome-file>index.jsp</welcome-file>

to

<welcome-file>map.xhtml</welcome-file>

This way map.xhtml becomes the welcome file and you can now stop fiddling with virtual URLs like .jsf and as a bonus, you can get rid of the legacy JSP file altogether.

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