This article is based on the implementation of the tomcat platform. The file directory is:
Under tom_homewebappsews:
└ Html
✓ WEB-INF
Classes
└ Com
Using FileMan. class
└ FileServlet. class
Web. xml
Next, modify web. xml to make filesevelet effective /*
<? 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>
Enter http: // localhost: 8080/news/servlet/FileServlet in the browser
OK. The following items are displayed: test.htm and OK can be found under newshtml!