码迷,mamicode.com
首页 > 其他好文 > 详细

Serverlet

时间:2016-02-28 22:42:38      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

1.web.xml配置。

技术分享

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

标签:

原文地址:http://www.cnblogs.com/zkzk945/p/5225742.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!