package scoreInfo;

import java.io.IOException;
import java.io.PrintWriter;

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

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class AddUserServlet extends HttpServlet{
	
public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    	
    String stu_id =req.getParameter("id");
    ///stu_id未注册时输入的学生号
   
    String action = req.getParameter("action");///////之后加的注释
    //////////////////String action = action = req.getParameter("action");
    student stu = null;
    teacher tea=null;
    String userkind= req.getParameter("kind");
   System.out.println(userkind+"regregreg");
    if ("new".equalsIgnoreCase(action)) {
    if(userkind.equalsIgnoreCase("student")){
      stu = doNew(req,res);
      sendBean(req, res, stu, "/login.jsp");
    }
    else if(userkind.equalsIgnoreCase("teacher")){
    	tea = doNewTea(req,res);
    	 sendBean(req, res, stu, "/login.jsp");
    	   }
    	
    }  
    
    }
    

 public student doNew(HttpServletRequest req,HttpServletResponse res )
                           throws ServletException,IOException{
      student stu= new student();  
      //////获取注册时在表单里输入的注册信息
      String stu_id=req.getParameter("id");  ///stu_id未注册时输入的学生号
      String name=new String(req.getParameter("name").getBytes("ISO8859_1"),"GBK");
      System.out.println(name+"regreg");
      String password= req.getParameter("password");
      String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"),"GBK");
      String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"),"GBK");
      String jiguan =""; 
    	jiguan= new String(req.getParameter("cmbProvince").getBytes("ISO8859_1"),"GBK");
    	 String cmbcity=new String(req.getParameter("cmbCity").getBytes("ISO8859_1"),"GBK");
    	 if(cmbcity==null||cmbcity.equals("市辖区")||cmbcity=="市辖区"||cmbcity.equals("县")||cmbcity=="县"){
    		 cmbcity="";
    	 }
    	 jiguan+=cmbcity;
    	 jiguan+= new String(req.getParameter("cmbArea").getBytes("ISO8859_1"),"GBK");
     /////System.out.println(jiguan+"regreg");
      String email= new String(req.getParameter("userEmail").getBytes("ISO8859_1"),"GBK");
      String tel= new String(req.getParameter("tel").getBytes("ISO8859_1"),"GBK");
     /// System.out.println(email+"regreg");
     //// String userkind= req.getParameter("kind");
    /// System.out.println(userkind+"regreg");
      ///if(userkind.equalsIgnoreCase("student")){
      if(isTrue(req,res,stu_id,name,password) && hasLogin(req,res,stu_id)){
      
      stu.setId(stu_id);
      stu.setName(name);
      stu.setPassword(password);
      stu.setDep(dep);
      stu.setSex(sex);
      stu.setE_mail(email);
      stu.setTel(tel);
      stu.setJiguan(jiguan);
      /////把注册表单时输入的信息用数据库语句添加到数据库中
    /// stu.addStudent(); 
      //stu.addStudentagain();
      stu.addStudent1();
      }  
      return stu;                	
     	}

 public teacher doNewTea(HttpServletRequest req,HttpServletResponse res )
 throws ServletException,IOException{
teacher tea= new teacher();  
//////获取注册时在表单里输入的注册信息
String tea_id=req.getParameter("id");  ///stu_id未注册时输入的学生号
String name=new String(req.getParameter("name").getBytes("ISO8859_1"),"GBK");
System.out.println(name+"regreg");
String password= req.getParameter("password");
String dep=new String (req.getParameter("dep").getBytes("ISO8859_1"),"GBK");
String sex = new String(req.getParameter("sex").getBytes("ISO8859_1"),"GBK");
//String jiguan = new String(req.getParameter("jiguan").getBytes("ISO8859_1"));
/// System.out.println(jiguan+"regreg");
String email= new String(req.getParameter("userEmail").getBytes("ISO8859_1"),"GBK");
String tel= new String(req.getParameter("tel").getBytes("ISO8859_1"),"GBK");
String title="教授";
/// System.out.println(email+"regreg");
//// String userkind= req.getParameter("kind");
/// System.out.println(userkind+"regreg");
///if(userkind.equalsIgnoreCase("student")){
if(isTrue(req,res,tea_id,name,password) && hasLogin(req,res,tea_id)){

	tea.setId(tea_id);
	tea.setName(name);
	tea.setPassword(password);
	tea.setDep(dep);
	tea.setSex(sex);
	tea.setTel(tel);
	tea.setE_mail(email);
	tea.setTitle(title);
	
/////把注册表单时输入的信息用数据库语句添加到数据库中
/// stu.addStudent(); 
//stu.addStudentagain();
tea.addTeaEnroll();
}  
return tea;                	
}
 
 
 
public void sendBean(HttpServletRequest req, HttpServletResponse res,
                       student stu, String target)
                       throws ServletException, IOException {
    req.setAttribute("stu", stu);
    RequestDispatcher rd = getServletContext().getRequestDispatcher(target);
    rd.forward(req, res);
  }
  
  
public void doError(HttpServletRequest req,
        HttpServletResponse res,
        String str)
        throws ServletException, IOException {


req.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(req, res);
}



  public boolean hasLogin(HttpServletRequest req, HttpServletResponse res,String id)
  throws ServletException, IOException{
  	boolean f=true;
  	String message="对不起,该学生号已经被注册过了!";
  	student stu= new student();
  	f= stu.hasLogin(id);
  	if(f==false){
  	doError(req,res,message);	
  		}
  		return f;
  	}
  
  public boolean isTrue(HttpServletRequest req, HttpServletResponse res,
                        String id,String name,String password)
                        throws ServletException, IOException {
   boolean f=true;                     	
   String message ="";
   if(id==null || id.equals(""))  {
   	f=false;
   	message="错误,学生号不能为空!";
   	doError(req,res,message);	}
   
   if(name==null || name.equals(""))  {
   	f=false;
   	message="学生姓名不能为空,请重新填写!";
   	doError(req,res,message);	}
  	
       
   if(password==null || password.equals(""))  {
   	f=false;
   	message="密码不能为空,请重新填写!";
   	doError(req,res,message);	}  

     return f;
     
  }
  
  public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

    this.doGet(req, res);

  }
	
	
}
最近下载更多
wcheng  LV2 2023年10月18日
lsj123456798  LV3 2022年12月30日
lyzzz520  LV1 2022年12月18日
485415187  LV6 2022年11月22日
微信网友_5970838873509888  LV2 2022年5月23日
微信网友_5764743416303616  LV6 2022年4月22日
roygugu  LV2 2022年4月9日
illkih  LV2 2022年3月17日
17771013609  LV4 2021年12月27日
CCCbbbcai  LV6 2021年12月23日
最近浏览更多
PROFKazami 4月15日
暂无贡献等级
张七七 4月13日
暂无贡献等级
暂无贡献等级
WBelong  LV7 3月8日
王冰冰0001 1月15日
暂无贡献等级
暂无贡献等级
kjsk001 2023年12月31日
暂无贡献等级
冯海涛 2023年12月31日
暂无贡献等级
qwerewqss 2023年12月30日
暂无贡献等级
asddwh  LV12 2023年12月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友