package com.hp.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.hp.bean.Student;
import com.hp.bean.Teacher;
import com.hp.db.DB;
public class studentInfo extends HttpServlet {
public void init() throws ServletException {
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String servletPath = request.getServletPath();
if (servletPath.equals("/Login")) {
DB findDb = new DB();
String user = request.getParameter("user");
String pw = request.getParameter("pw");
if (user == null || user == "" || pw == null || pw == "") {
request.setAttribute("Att_login_message", "请补全登陆信息");
RequestDispatcher dispatcher_login = request.getRequestDispatcher("/Login.jsp");
if(dispatcher_login!=null){
dispatcher_login.forward(request, response);
return;
}
} else {
String Name = new String(user.getBytes("ISO-8859-1"), "utf-8");
String Pass = new String(pw.getBytes("ISO-8859-1"), "utf-8");
boolean findYesOrFalse = findDb.find(Name, Pass);
if (findYesOrFalse) {
String stuOrTea = new String(request.getParameter("login_type").getBytes("ISO-8859-1"), "utf-8");
if (stuOrTea.equals("学生")) {
servletPath = "/StudentInfo.jsp";
} else if (stuOrTea.equals("教师")) {
servletPath = "/TeacherInfo.jsp";
}
request.setAttribute("Att_login_pass",Pass);
request.setAttribute("Att_login_user",Name);
}else{
request.setAttribute("Att_login_message", "用戶名或密码错误");
RequestDispatcher dispatcher_login_error = request.getRequestDispatcher("/Login.jsp");
if(dispatcher_login_error!=null){
dispatcher_login_error.forward(request, response);
return;
}
}
}
}else if(servletPath.equals("/Register")){
String register_user_no = request.getParameter("register_user");
String register_pass_no = request.getParameter("register_pass1");
if(register_user_no==null||register_user_no==""||register_pass_no==null||register_pass_no==""){
request.setAttribute("Att_register_error","请补全注册信息");
servletPath = "/Register.jsp";
}else{
String register_user = new String(request.getParameter("register_user").getBytes("ISO-8859-1"),"utf-8");
String register_pass1 = request.getParameter("register_pass1");
String register_pass2 = request.getParameter("register_pass2");
if(!register_pass1.equals(register_pass2)){
request.setAttribute("Att_register_error","两次密码不一致");
RequestDispatcher dispatcher_pass = request.getRequestDispatcher("/Register.jsp");
if(dispatcher_pass!=null){
dispatcher_pass.forward(request, response);
return;
}
}else{
DB registerDb = new DB();
boolean RegTrueOrFalse = registerDb.register(register_user, register_pass1);
if(RegTrueOrFalse){
servletPath = "/Login.jsp";
request.setAttribute("Att_register_message","用户:"+register_user+" 注册成功");
}else{
servletPath = "/Register.jsp";
request.setAttribute("Att_register_error","该用户已被注册");
}
}
}
}else if(servletPath.equals("/addInfo")){
String addId = request.getParameter("addId");
String add_login_pass = request.getParameter("add_login_pass");
String add_login_user =new String(request.getParameter("add_login_user").getBytes("iso-8859-1"),"utf-8");
if(addId==null){
request.setAttribute("Att_add_login_pass",add_login_pass);
request.setAttribute("Att_add_login_user",add_login_user);
String login_stu_tea = new String(request.getParameter("login_stu_tea").getBytes("iso-8859-1"),"utf-8");
if(login_stu_tea.equals("学生")){
servletPath = "/addStuInfo.jsp";
}else{
servletPath = "/addTeaInfo.jsp";
}
}else{
request.setAttribute("Att_login_pass",add_login_pass);
request.setAttribute("Att_login_user",add_login_user);
String login_stu_tea_add = new String(request.getParameter("login_stu_tea_add").getBytes("ISO-8859-1"),"utf-8");
if(login_stu_tea_add.equals("学生")){
String addStuName = new String(request.getParameter("addStuName").getBytes("iso-8859-1"),"utf-8");
String addStuClass = new String(request.getParameter("addStuClass").getBytes("iso-8859-1"),"utf-8");
DB addStuDb = new DB();
addStuDb.addStuInfo(addId, addStuName, addStuClass);
servletPath = "/StudentInfo.jsp";
}else{
String addTeaName = new String(request.getParameter("addTeaName").getBytes("iso-8859-1"),"utf-8");
String addTeaPhone = request.getParameter("addTeaPhone");
DB addTeaDb = new DB();
addTeaDb.addTeaInfo(addId, addTeaName, addTeaPhone);
servletPath = "/TeacherInfo.jsp";
}
}
}else if(servletPath.equals("/deleteInfo")){
String delete_login_user = new String(request.getParameter("delete_login_user").getBytes("ISO-8859-1"),"utf-8");
String delete_login_pass = request.getParameter("delete_login_pass");
int deleteId =Integer.parseInt(request.getParameter("deleteId"));
String delete_stu_tea = new String(request.getParameter("delete_stu_tea").getBytes("iso-8859-1"),"utf-8");
DB delete_info_db = new DB();
delete_info_db.deleteInfo(deleteId, delete_stu_tea);
if(delete_stu_tea.equals("学生")){
servletPath = "/StudentInfo.jsp";
}else{
servletPath = "/TeacherInfo.jsp";
}
request.setAttribute("Att_login_pass",delete_login_pass);
request.setAttribute("Att_login_user",delete_login_user);
}else if(servletPath.equals("/updateInfo")){
int update_Id = Integer.parseInt(request.getParameter("update_Id"));
String update_login_user = new String(request.getParameter("update_login_user").getBytes("iso-8859-1"),"utf-8");
String update_login_pass = request.getParameter("update_login_pass");
String update_stu_tea = new String(request.getParameter("update_stu_tea").getBytes("iso-8859-1"),"utf-8");
if(request.getParameter("update_biaoji")==null){
if(update_stu_tea.equals("学生")){
String update_StuId_first = request.getParameter("update_StuId");
String update_StuName_first = new String(request.getParameter("update_StuName").getBytes("iso-8859-1"),"utf-8");
String update_StuClass_first = new String(request.getParameter("update_StuClass").getBytes("iso-8859-1"),"utf-8");
request.setAttribute("Att_update_StuId",update_StuId_first);
request.setAttribute("Att_update_StuName",update_StuName_first);
request.setAttribute("Att_update_StuClass",update_StuClass_first);
servletPath = "/updateStu.jsp";
}else{
String update_TeaId_first = request.getParameter("update_TeaId");
String update_TeaName_first = new String(request.getParameter("update_TeaName").getBytes("iso-8859-1"),"utf-8");
String update_TeaPhone_first = new String(request.getParameter("update_TeaPhone").getBytes("iso-8859-1"),"utf-8");
request.setAttribute("Att_update_TeaId",update_TeaId_first);
request.setAttribute("Att_update_TeaName",update_TeaName_first);
request.setAttribute("Att_update_TeaPhone",update_TeaPhone_first);
servletPath = "/updateTea.jsp";
}
request.setAttribute("Att_update_Id",update_Id);
request.setAttribute("Att_update_login_pass",update_login_pass);
request.setAttribute("Att_update_login_user",update_login_user);
}else{
if(update_stu_tea.equals("学生")){
String update_StuId = request.getParameter("update_StuId");
String update_StuName = new String(request.getParameter("update_StuName").getBytes("iso-8859-1"),"utf-8");
String update_StuClass = new String(request.getParameter("update_StuClass").getBytes("iso-8859-1"),"utf-8");
DB update_stu_db