如何在eclipse中更改默认启动页面?

时间:2015-01-19 07:39:20

标签: java xml eclipse jsp

您好我正在尝试将eclipse中我的动态项目的默认启动页面从index.jsp更改为welcome.jsp。我已经在网上找到了一些答案,我相应地更改了欢迎文件列表,但仍无法正常工作。

我的web.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Decryption</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    **<welcome-file>welcome.jsp</welcome-file>**
  </welcome-file-list>
</web-app>

我已经编辑了欢迎文件列表,我已经添加了<welcome-file>welcome.jsp</welcome-file>。但它仍然不起作用。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

列出<welcome-file-list>条目的顺序非常重要,因为网络容器从上到下查看此列表,并在第一场比赛时停止搜索。

因此,如果您的网络内容目录包含之前列出的其他文件,例如index.jsp,则不会提供welcome.jsp。因此,只需将条目移至顶部即可解决您的问题。

<welcome-file-list>
  <welcome-file>welcome.jsp</welcome-file>

  <welcome-file>index.html</welcome-file>
  <welcome-file>index.htm</welcome-file>
  <welcome-file>index.jsp</welcome-file>
  <welcome-file>default.html</welcome-file>
  <welcome-file>default.htm</welcome-file>
  <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

顺便说一句,您也可以选择删除所有其他条目,并保留指向索引文件的条目。列出所有条目不是​​强制性的。

答案 1 :(得分:0)

正如Ravi所说,文件顺序在web.xml中很重要 因此,如果您希望显示welcome.jsp,请将此条目保留为第一行 <welcome-file-list>标记。

<welcome-file-list>标记下包含index.html,index.htm,index.jsp ....等所有文件也不是强制性的。如果你知道你的主页,那么你只能添加一个jsp,如下所示。

<welcome-file-list>
  <welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>

注意: 另外作为建议你应该将你的jsp放在web-inf文件夹下。 有关详细信息,请参阅URL