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);
}
}