如何更改我的Web项目的起始页?

时间:2011-05-25 09:49:23

标签: java eclipse jsf jsf-2 java-ee-6

当我在eclipse中创建一个新项目时,它会自动为我创建一个index.jsp页面,我不希望起始页面是.jsp,我希望它是一个.xhtml 这就是我在web.xml上所做的:

<web-app version="3.0" 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-app_3_0.xsd">
<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>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>myStartPage.xhtml</welcome-file>
</welcome-file-list>
</web-app> 

当我在localhost中运行项目时,上面的代码不允许我将页面myStartPage.xhtml看作第一页。

我应该如何修改此浏览器以便为我显示起始页面。 此外,我不想使用任何网址模式。这是强制性的吗?(我尝试删除该标签,但它没有构建)。

2 个答案:

答案 0 :(得分:5)

尝试这个servlet映射:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

这适用于Glassfish 3。

答案 1 :(得分:1)

据我所知,将始终显示index.jsp。您可以将重定向添加到index.jsp:

<% response.sendRedirect("myStartPage.xhtml"); %>

但可能有更好的解决方案。

相关问题