0

I have tried to find a solution searching on Google, but did not succeed.

This is the structure of my application's folder.

<PROJECT_NAME>
--->WebContent
    --->index.html
    --->WEB-INF
    --->META-INF

I deployed my application in Tomcat server.

My web.xml config file is the following:

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>fp</display-name>
  <servlet>
    <servlet-name>FpServlet</servlet-name>
    <servlet-class>com.fp.FpServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>FpServlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

I try to access localhost:8080/project_name/,and everything works fine, but when I try to access the index.html file like this localhost:8080/project_name/index.html, it doesn't show the index.html content. It shows my root project content. (localhost:8080/project_name/)

How can I get the index file content posted in the browser?

Any help will be very appreciated.

4

2 回答 2

1

请注意,该文件夹名为“WEB-INF”,而不是“WEB.INF”。

于 2013-11-06T13:12:53.760 回答
0

您可以使用默认 servlet 来提供静态资源。这是如何与 tomcat 一起使用的:

<servlet>
    <servlet-name>default</servlet-name>
    <servlet-class>
      org.apache.catalina.servlets.DefaultServlet
    </servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
    <url-pattern>*.htm</url-pattern>
</servlet-mapping>
于 2013-11-06T07:17:06.857 回答