看透SpringMVC系列(二)详解Servlet

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27605885/article/details/79575111

Servlet是Server+Applet的缩写,表示一个服务器应用。Servlet其实就是一套规范。我们按照这套规范些代码就可以直接在Java的服务器上面运行了。Servlet结构图:


Servlet接口定义:

 
 
public interface Servlet{
    public void init(ServletConfig config)throws ServletException;
    public void service(ServletRequest req, ServletResponse res)throws ServletException,IOException;
    public String getServletInfo();
    public void destroy();
}

init方法在容器启动时被容器调用(当load-on-startup设置为负数或者不设置时会在Servlet第一次用到时候才被调用),只会调用一次;

getServletConfig方法用于获取ServletConfig

service方法用来处理具体请求;

getServletInfo获取以下Servlet相关的信息,如作者版权等,需要自己实现。默认返回空字符串



猜你喜欢

转载自blog.csdn.net/qq_27605885/article/details/79575111