【问题标题】:eclipse dynamic web project - default start pageeclipse 动态 web 项目 - 默认起始页
【发布时间】:2012-07-22 20:26:06
【问题描述】:

我在 Eclipse 动态 web 项目中创建,我在 WEB-INF 文件夹中有 index.html。我单击项目的主文件夹 Run as > Run on server 选择 Tomcat v7.0,完成,它运行正常。但是,当我将 index.html 重命名为另一个名称时,我会收到以下消息:

请求的资源 (/MyProject/) 不可用。

  1. 如何更改默认页面?
  2. 我可以放入默认页面asp文件吗?

我的 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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>MyFirstServlet</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-list>
  <servlet>
    <description>new</description>
    <display-name>GrettingServlet</display-name>
    <servlet-name>GrettingServlet</servlet-name>
    <servlet-class>GrettingServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>GrettingServlet</servlet-name>
    <url-pattern>/GrettingServlet</url-pattern>
  </servlet-mapping>
</web-app>

【问题讨论】:

    标签: java eclipse jsp project


    【解决方案1】:

    在 web.xml(在 TOMCAT_HOME/webapps/you_application 下)你有这个:

    <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>/axis2-web/index.jsp</welcome-file>
      </welcome-file-list>
    

    更改为您的新文件名

    【讨论】:

    • 如果 index.html 没有找到它去下一个等等?
    【解决方案2】:

    1) 如何更改默认页面?

    => 更改 web.xml 中的欢迎文件列表。更改为您想要使用的文件名。

    2) 我可以把默认页面的asp文件放进去吗?

    => 您可以将扩展名更改为 asp,但您需要在 web.xml 中进行 servlet 映射。但是,如果您在谈论Microsoft ASP pages,我认为您将无法根据我的知识添加它们,因为两者(jsp 和 asp)都驻留在不同的技术下

    编辑:

    <?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>MyFirstServlet</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-list>
      <servlet>
        <description>new</description>
        <display-name>GrettingServlet</display-name>
        <servlet-name>GrettingServlet</servlet-name>
        <servlet-class>GrettingServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>GrettingServlet</servlet-name>
        <url-pattern>/greetings.asp</url-pattern>
      </servlet-mapping>
    </web-app>
    

    在这里,您将使用 url http://localhost:8080/myapp/greetings.aspGreetingServlet 发出请求

    【讨论】:

    • 你能解释一下我必须在 servlet 映射中写什么吗?我编辑了我的帖子并添加了 web.xml 。
    • @NandkumarTekale 很抱歉写评论给您带来麻烦。我确定如果我写了一个问题,那么它将被关闭。我已经开发了一个带有 servlet 和 JSP 的项目,但现在我对要做什么感到困惑运行以启动应用程序。从某种意义上说,如果我运行 JSP,那么当我运行 servlet 时,应该来自 servlet 的数据不会再次被加载,但是 JSP 中的一些 javascript 函数不会被调用。现在我的困惑是应该运行什么来启动应用程序,我应该运行 JSP 作为默认页面还是 servlet 作为默认页面以及建议的方法。请指导
    【解决方案3】:

    几件事情要检查。

    1) Servlet mapping extension in web.xml
    2) Welcome file definition in web.xml
    

    确保扩展名和名称与您更改的一致。

    web.xml 将位于 WEB-INF 文件夹内。

    【讨论】:

    • 我那里没有 web.xml .. 如果我使用 Tomcat 7 可以在哪里找到他?
    • web.xml 将在您的项目中--->WEB-INF 文件夹中。如果不存在,则需要创建一个并添加欢迎文件定义。
    【解决方案4】:

    当出现 404 错误时也会发生这种情况,Tomcat 默认搜索索引文件。 jsp/html ,您必须从 Tomcat Eclipse 的 web.xml 文件中的 Tomcat 文件夹或安装的文件夹系统中更改它(c/files Program/apache...) o look at this example

    【讨论】:

      【解决方案5】:

      打开Eclipse->点击服务器->在localhost-config选择Tomcat v9.0 Server->选择"web.xml"->滚动到底部或者找到" "-> "filename.xml"

      【讨论】:

        猜你喜欢
        • 2013-02-16
        • 1970-01-01
        • 2011-01-13
        • 1970-01-01
        • 2021-06-23
        • 2011-05-20
        • 1970-01-01
        • 2014-10-07
        • 2011-11-08
        相关资源
        最近更新 更多