本文是根據tomcat平台下實現而做,文件目錄為:
tom_homewebapps
ews下:
└html
└WEB-INF
└classes
└com
└FileMan.class
└FileServlet.class
└web.xml
下面開始修改web.xml令filesevelet生效/*
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<!-- JSPC servlet mappings start -->
<servlet>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<servlet-class>org.apache.jsp.index_jsp</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>org.apache.jsp.index_jsp</servlet-name>
<url-pattern>/index.jsp</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FileServlet</servlet-name>
<servlet-class>com.FileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FileServlet</servlet-name>
<url-pattern>/servlet/FileServlet</url-pattern>
</servlet-mapping>
<!-- JSPC servlet mappings end -->
</web-app>
在浏覽器中輸入:http://localhost:8080/news/servlet/FileServlet
OK,出現以下面面:同時 在newshtml下可以找到test.htm,OK,成功!