protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("GBK");
String name = request.getParameter("textfield1");
String pwd = request.getParameter("textfield2");
String head = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
Sql sql = new Sql();
PrintWriter out = response.getWriter();
Connection conn = DbUtil.getConnection();
try {
PreparedStatement ps = conn.prepareStatement(sql.getInsert());
PreparedStatement ps2 = conn.prepareStatement(sql.getSelect());
ps.setObject(1,name);
ps.setObject(2,pwd);
ps2.setObject(1,name);
ResultSet rs = ps2.executeQuery();
if (rs.next()){
response.getWriter().write("<script > alert(\"用户已经存在!请重新输入用户名!\");location='register.jsp';</script>");
}else{
ps.execute();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
### response.getWriter().write("<script > alert(\"用户已经存在!请重新输入用户名!\");location='register.jsp';</script>");