【问题标题】:How to change the default startup page in eclipse?如何更改eclipse中的默认启动页面?
【发布时间】:2015-03-17 04:18:54
【问题描述】:

您好,我正在尝试将我在 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>

我已经编辑了欢迎文件列表,并在其中添加了&lt;welcome-file&gt;welcome.jsp&lt;/welcome-file&gt;。但它仍然无法正常工作。任何帮助将不胜感激。

【问题讨论】:

    标签: java xml eclipse jsp


    【解决方案1】:

    列出 &lt;welcome-file-list&gt; 条目的顺序很重要,因为 Web 容器会从上到下查看此列表,并在第一次匹配时停止搜索。

    因此,如果您的 Web 内容目录有另一个之前列出的文件,例如 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>
    

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

    【讨论】:

    • 不,这对我不起作用。同样的事情正在发生,它正在显示目录列表。
    • 您在浏览器中使用的确切 URL 是什么?
    • localhost:8080/Decryption .. 解密为项目名称。我只是在 eclipse 上运行这个东西,默认浏览器正在访问这个 url
    • 您将获得/ 的目录列表,即您是否将/welcome.jsp 视为其中一个文件?
    • 您能否验证tomcat_install_dir/webapps/Decryption/WEB-INF/web.xmlweb.xml 是否有您所做的更改?
    【解决方案2】:

    正如 Ravi 所说,web.xml 中的文件顺序很重要 因此,如果您希望显示welcome.jsp,则将此条目保留为第一行 &lt;welcome-file-list&gt; 标签。

    也不是必须在&lt;welcome-file-list&gt; 标签下包含所有文件,如 index.html、index.htm、index.jsp .... 等。如果你知道你的主页,那么你可以只添加一个jsp,如下所示。

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

    注意: 另外作为建议,您应该将 jsp 放在 web-inf 文件夹下。 详情请参考URL

    【讨论】:

      猜你喜欢
      • 2012-03-23
      • 2017-07-11
      • 2018-11-06
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 2012-10-27
      相关资源
      最近更新 更多