eclipse 如何更改我的 Web 项目的起始页?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6122499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the start page of my web project?
提问by sfrj
When i created a new project in eclipse, it automatically created for me an index.jsp page, i don't want the start page to be a .jsp, i want it to be a .xhtml This is what i did at the web.xml:
当我在 Eclipse 中创建一个新项目时,它会自动为我创建一个 index.jsp 页面,我不希望起始页面是 .jsp,我希望它是 .xhtml 这就是我在网络上所做的.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>
The above code does not allow me to see the page myStartPage.xhtml as the first page when i run the project in localhost.
当我在本地主机中运行项目时,上面的代码不允许我将页面 myStartPage.xhtml 视为第一页。
How should i modify this for the browser to display for me the start page. Also i dont want to use any url-pattern. Is that mandatory?(I tried removing that tag, but it did not build).
我应该如何修改它以便浏览器为我显示起始页。我也不想使用任何 url-pattern。这是强制性的吗?(我尝试删除该标签,但它没有建立)。
采纳答案by McDowell
Try this servlet mapping:
试试这个 servlet 映射:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
This works in Glassfish 3.
这适用于 Glassfish 3。
回答by morja
As far as I know always the index.jsp will be shown. You can add a redirect to the index.jsp:
据我所知,将始终显示 index.jsp。您可以向 index.jsp 添加重定向:
<% response.sendRedirect("myStartPage.xhtml"); %>
But there might be a nicer solution.
但可能有更好的解决方案。