0

我无法正确设置我的应用程序欢迎文件以正确重定向到我的 home.xhtml 我试图在 SO 中搜索,但我似乎无法让它工作..对不起..

在我的 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

我什么也没得到,也没有重定向。

有什么问题?

4

2 回答 2

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 输出并在 webbrowser 中查看源代码,那么您应该已经注意到 JSTL XML 命名空间和标记根本没有被解析,并且在 HTML 输出中看起来很普通。

于 2012-11-08T12:50:46.173 回答
1

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

于 2012-11-08T10:35:35.497 回答