Serverlet

1.web.xml配置。

Serverlet_第1张图片

2.Serverlet源码

  service函数是对客户端请求的响应代码。

package com.zkzk945.Serverlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Serverlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
        // TODO Auto-generated method stub
        System.out.println("service");
//        super.service(arg0, arg1);
        
//        System.out.println("hello world");
        PrintWriter pw = arg1.getWriter();
        pw.println("hello world");
        pw.close();
    }

    @Override
    public void destroy() {
        // TODO Auto-generated method stub
        System.out.println("destroy");
        super.destroy();
    }

    @Override
    public void init() throws ServletException {
        // TODO Auto-generated method stub
        System.out.println("init no params");
        super.init();
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        System.out.println("init with params");
        super.init(config);
    }

}

 3.源码

  https://git.oschina.net/zkzk945/JavaEE.git

你可能感兴趣的:(Serverlet)