11

我在 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>
4

5 回答 5

14

在 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>

更改为您的新文件名

于 2012-07-24T13:50:24.770 回答
5

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>

在这里您将请求GreetingServlet使用 urlhttp://localhost:8080/myapp/greetings.asp

于 2012-07-24T13:50:32.290 回答
3

几件事情要检查。

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

确保扩展名和名称与您更改时一样。

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

于 2012-07-24T13:47:57.527 回答
0

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

于 2019-11-25T23:21:49.310 回答
0

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

图片

于 2020-09-17T12:36:20.860 回答