⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginservlet.java

📁 学生考勤管理系统————分为课程选择
💻 JAVA
字号:
package com.ccniit.kaoqin.servlet;

import java.io.IOException;
import java.sql.SQLException;

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

import com.ccniit.kaoqin.db.teacher.Teacher;
import com.ccniit.kaoqin.db.teacher.TeacherDAO;

@SuppressWarnings("serial")
public class LoginServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		         
		     String successPage="/fram.jsp";
		     String errorPage="/index.jsp";
		     
		     String errorMessage="";
		     
		     
		     String userName=request.getParameter("userName");
		    
		     String userType_Str=request.getParameter("userType");
		     int userType=Integer.parseInt(userType_Str);
		     String password=request.getParameter("password");
		     
		     TeacherDAO teacherDAO=null;
		     Teacher teacher=null;
		     teacherDAO=new TeacherDAO();
		     try {
		    	  
		        teacher=teacherDAO.getTeacherByEmail(userName);
		        
		              if(userType==1){
		            	  
		            	  if(teacher==null){
								errorMessage="用户不存在";
								request.setAttribute("message", errorMessage);
								request.getRequestDispatcher(errorPage).forward(request, response);

							 
						 }
						  else if(password.equals(teacher.getTeacher_password())){
							  HttpSession session = request.getSession();
							  session.setMaxInactiveInterval(600000000);
							  request.getSession().setAttribute("teacher",teacher);
							  request.getRequestDispatcher(successPage).forward(request, response); 
					             
					       } else{
					    	    errorMessage="密码错误";
								request.setAttribute("message", errorMessage);
								request.getRequestDispatcher(errorPage).forward(request, response);
                                
					       }
		              }else if(userType==2){
		            	  
		            	  request.getRequestDispatcher(errorPage).forward(request, response);

		            	  
		              }else if(userType==0){
		            	  
		            	  request.getRequestDispatcher(errorPage).forward(request, response);
		            	  
		              }else{
		            	  request.getRequestDispatcher("/share/error.jsp").forward(request, response);
		              }
		            
		              
		              
			} catch (ClassNotFoundException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}finally{
				try {
					if(teacherDAO!=null)
						teacherDAO.release();
				} catch (SQLException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			}
		     
		        
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

	      request.setCharacterEncoding("gb2312");
	      this.doGet(request, response);
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -