编写入门案例
1)编写java类,继承HttpServlet类
2)重新doGet和doPost方法
3)Servlet程序交给tomcat服务器运行!!
3.1 servlet程序的class码拷贝到WEB-INF/classes目录
3.2 在web.xml文件中进行配置
package com.loaderman.demo;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { //向浏览器输出内容 response.getWriter().write("this is first servlet!"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doGet(req, resp); }}
mTestServlet com.loaderman.demo.TestServlet mTestServlet /demotest