1.在tomcat中(webapps文件夹)新建一个mail应用,然后在web应用中新建一个WEB-INF、classes目录。
2.在classes目录中新建一个FirstServlet
3.set classpath=%classpath%;.......servlet.jar 编译servlet
4.在WEB-INF目录中新建一个web.xml文件,配置servlet对外访问路径
5.启动tomcat,访问
2.在classes目录中新建一个FirstServlet
package cn.itcast; import java.io.*; import javax.servlet.*; public class FristServlet extends GenericServlet{ public void service(ServletRequest req,ServletResponse res) throws ServletException,java.io.IOException { OutputStream out =res.getOutputStream(); out.write("hello servlet!!!!".getBytes()); } }
3.set classpath=%classpath%;.......servlet.jar 编译servlet
4.在WEB-INF目录中新建一个web.xml文件,配置servlet对外访问路径
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>FristServlet</servlet-name> <servlet-class>cn.itcast.FristServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>FristServlet</servlet-name> <url-pattern>/FristServlet</url-pattern> </servlet-mapping> </web-app>
5.启动tomcat,访问