package com;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
<!--more-->
public class JavaRegisterMysql extends HttpServlet{
private static final long serialVersionUID = 1L;
private static final int NAME_CODE_RIGHT = 0;
private static final int CODE_WRONG = 1;
private static final int NAME_WRONG = 2;
String notename = null;
String notepassword = null;
String notephone = null;
public JavaRegisterMysql(){
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if(req == null){
return;
}
resp.setContentType("text/html;charset=utf-8");
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
String name = req.getParameter("NAME");
String code = req.getParameter("CODE");
String phone = req.getParameter("PHONE");
String chose=req.getParameter("CHOSE");
int ret=-1;
try {
ret = checkSubmit(name, code, phone, chose);
} catch (Exception e) {
e.printStackTrace();
}
out.print(ret);
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if(req == null){
return;
}
resp.setContentType("text/html;charset=utf-8");
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
PrintWriter out = resp.getWriter();
String name = req.getParameter("NAME");
String code = req.getParameter("CODE");
String phone = req.getParameter("PHONE");
String chose=req.getParameter("CHOSE");
int ret=-2;
try {
ret = checkSubmit(name, code, phone,chose);
} catch (Exception e) {
e.printStackTrace();
}
out.print(ret);
out.flush();
out.close();
}
* 判断登录名和密码
* @param name
* @param code
* @return
* @throws Exception
*/
private int checkSubmit(String name, String code, String phone,String chose) throws Exception{
int ret = -1;
User user=new User(name,code,phone);
ret=new UserDAOProxy().findLogin(user, chose);
return ret;
}
}