Chinaunix首页 | 论坛 | 博客
  • 博客访问: 418411
  • 博文数量: 121
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-11 12:17
个人简介

www.vibexie.com vibexie@qq.com

文章分类

全部博文(121)

文章存档

2015年(55)

2014年(66)

我的朋友

分类: Java

2015-04-16 19:34:06


  1. package com.vibexie.jianaiServer.register;

  2. import java.io.BufferedOutputStream;
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.io.PrintWriter;

  6. import javax.servlet.ServletException;
  7. import javax.servlet.annotation.WebServlet;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;

  11. /**
  12.  * Servlet implementation class RegisterServlet
  13.  */
  14. @WebServlet("/RegisterServlet")
  15. public class RegisterServlet extends HttpServlet {
  16. private static final long serialVersionUID = 1L;
  17.     
  18.     /**
  19.      * servlet初始化的相关设置
  20.      */
  21.     @Override
  22.     public void init() throws ServletException {
  23.         super.init();
  24.         System.out.println("RegisterServlet启动成功");
  25.     }
  26.     
  27.     /**
  28.      * 以get方式访问页面时会先执行此函数,如果浏览器发现getLastModified返回的数值和上次的一样,则不执行doget(),如果getLastModified返回-1,则认为是总是更新的
  29.      */
  30.     @Override
  31.     protected long getLastModified(HttpServletRequest req) {
  32.         return super.getLastModified(req);
  33.     }
  34.     
  35.     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  36.         this.execute(request, response);
  37.     }

  38.     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  39.         this.execute(request, response);
  40.     }

  41.     /**
  42.      * get和post共同的执行
  43.      * @param request
  44.      * @param response
  45.      * @throws ServletException
  46.      * @throws IOException
  47.      */
  48.     private void execute(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
  49.         /**
  50.          * 设置request和response的字符编码
  51.          */
  52.         request.setCharacterEncoding("UTF-8");
  53.         response.setCharacterEncoding("UTF-8");
  54.         response.setContentType("text/html;charset=utf-8");
  55.         
  56.         /**
  57.          * 回写流
  58.          */
  59.         OutputStream outputStream=response.getOutputStream();
  60.         
  61.         String userName=request.getParameter("userName");
  62.         String email=request.getParameter("email");
  63.         
  64.         
  65.         outputStream.close();
  66.     }
  67. }

阅读(1613) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~