出自:淘特网
作者:[url=http://www.tot.name]淘特网声明:转载请注明出处。
本文是根据tomcat平台下实现而做,文件目录为:
tom_home\webapps\news下:
└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,出现以下面面:
同时 在news\html\下可以找到test.htm,OK,成功!