RegisterDemo

package com.java.contorl;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

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

import com.java.domain.User;

/**

  • Servlet implementation class registerDemo
    */
    public class RegisterDemo extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(“text/html;charset=utf-8”);//设置浏览器的编码和response
    request.setCharacterEncoding(“utf-8”);

     String username = request.getParameter("username");
     String password = request.getParameter("password");
     String birthday  = request.getParameter("birthday");
     String gender = request.getParameter("gender");
     String[] hobbies = request.getParameterValues("hobby");
     String hobby = Arrays.toString(hobbies);
     String address = request.getParameter("address");
     String remark = request.getParameter("remark");
     
     /*System.out.println(username);
     System.out.println(password);
     System.out.println(gender);
     System.out.println(hobby);
     System.out.println(address);
     System.out.println(remark);*/
     
     User user =  new User();
     user.setUsername(username);
     user.setPassword(password);
     //将字符串转换为日期时间型
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");//"yyyy-MM-dd HH:mm:ss.SSS"
     Date birthday_new = null;
     try {
     	birthday_new = sdf.parse(birthday);
     } catch (ParseException e) {
     	// TODO Auto-generated catch block
     	e.printStackTrace();
     }
     user.setGender(gender);
     user.setBirthday(birthday_new);
     user.setAddress(address);
     user.setHobby(hobby);
     user.setRemark(remark);
     System.out.println(user);
     
     //怎样将util的时间转化为sql的时间
     Date date = new Date();
     System.out.println(date);
     java.sql.Date sqlDate = new java.sql.Date(date.getTime());
     System.out.println(sqlDate);
    

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

     doGet(request, response);
    

    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值