2012-11-08 23 views
0

我无法正确设置我的应用程序文件表示欢迎妥善重定向到我home.xhtml 我试图内SO搜索,但我似乎无法使它work..sorry ..JSF欢迎文件没有正确重定向

在我的web.xml,我有这些

<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> 

我的index.jsp有这样

<%@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> 

当我进入我的应用程序:

http://localhost:8080/myApp 

我没有收到任何东西,也没有重定向。

什么可能是错的?

+1

看看[这里](http://stackoverflow.com/questions/7416369/redirecting-using-jstl-core-redirect#answer-7416537)! ,我认为这是相同类型的问题。 – tartak

回答

3

您在JSP中使用Facelets XML命名空间语法。这不起作用。使用JSP @taglib语法。

<%@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> 

如果你已经探索通过右击并在网页浏览器查看源代码检索输出HTML,那么你应该已经注意到,JSTL XML命名空间和标签都没有在所有的解析和显示普通的香草HTML输出。

+0

谢谢......对不起和JSP和JSF概念搞砸了。我不确定什么是在JSF中设置欢迎文件的正确方法 –

1

有时在列表中也需要有一个index.jsf。

+0

如果OP试图将JSF页面用作'',那么'FacesServlet' URL模式是虚拟的而不是真实的模式。另请参阅此答案:http://stackoverflow.com/questions/7885874/jsf-welcome-file-not-recognized/7889247#7889247但是,在这种情况下,OP试图使用普通的vanilla JSP页面作为“'。 – BalusC