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

  }
	
	
}
最近下载更多
123456cjj  LV1 6月2日
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日
最近浏览更多
sariel_zeng 7月7日
暂无贡献等级
asdfgh112 7月4日
暂无贡献等级
时光海  LV2 6月30日
taoshen95  LV15 6月25日
suhaifeng 6月21日
暂无贡献等级
15719908287  LV9 6月19日
xzg123456  LV6 6月18日
暂无贡献等级
你好啊213123 6月4日
暂无贡献等级
123456cjj  LV1 6月1日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友