一、Servlet介绍
什么是Servlet
1、Servlet是JavaEE规范之一。规范就是接口
2、Servlet就JavaWeb三大组件之一。三大组件分别是:Servlet程序、Filter过滤器、Listener监听器。
3、Servlet是运行在服务器上的一个java小程序,它可以接收客户端发送过来的请求,并响应数据给客户端。
手动实现Servlet程序
1、编写一个类去实现Servlet接口
public class HelloServlet implements Servlet{
@Override
public void service(ServletRequestservletRequest,ServletResponseservletResponse)throws ServletException,IOException{
System.out.println("HelloServlet被访问了");
}
}
2、实现service方法,处理请求,并响应数据
3、到web.xml中去配置servlet程序的访问地址
<?xmlversion="1.0"encoding="UTF-8"?>
<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.