0

I am having trouble properly setting my apps welcome file to properly redirect to my home.xhtml I tried to search within SO but I cant seem to make it work..sorry..

In my web.xml, I have these

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

My index.jsp has this

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:jsp="http://java.sun.com/JSP/Page"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<head>
<title>My App</title>
</head>
<body>
    <c:redirect url="/faces/pages/home.xhtml"></c:redirect>
</body>
</html>

When I access my app:

http://localhost:8080/myApp

I am getting nothing and it is not redirecting.

What could be wrong?

Mark Estrada
  • 9,013
  • 37
  • 119
  • 186
  • 1
    take a look [here](http://stackoverflow.com/questions/7416369/redirecting-using-jstl-core-redirect#answer-7416537)! ,I think it's the same type of issue. – tartak Nov 08 '12 at 09:57

2 Answers2

3

You're using Facelets XML namespace syntax in JSP. This won't work. Use JSP @taglib syntax.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
    <c:redirect url="/faces/pages/home.xhtml"></c:redirect>
</body>
</html>

If you'd have explored the retrieved HTML output by rightclick and View Source in webbrowser, then you should have noticed that the JSTL XML namespace and tag are not been parsed at all and appear plain vanilla in the HTML output.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks...sorry got messed up with both JSP and JSF concept.. I am not exactly sure whats the proper way of setting welcome file in JSF – Mark Estrada Nov 09 '12 at 07:06
1

Sometimes there needs to be an index.jsf in the list too.

Florian
  • 1,827
  • 4
  • 30
  • 62
  • This is only the case if the OP attempted to use a JSF page as `` whereby the `FacesServlet` URL pattern is a virtual one instead of a real one. See also this answer: http://stackoverflow.com/questions/7885874/jsf-welcome-file-not-recognized/7889247#7889247 However, in this case the OP attempted to use a plain vanilla JSP page as ``. – BalusC Nov 08 '12 at 12:53