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

📄 login_confirm.java

📁 毕业设计:Java成绩管理系统MSSQL版
💻 JAVA
字号:
package result;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 * 登录验证
 * @author
 *
 */
public class login_confirm extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doPost(HttpServletRequest request, HttpServletResponse responseres)
			throws ServletException, IOException {

		String message = "";
		String id = "";
		id = request.getParameter("id");
		HttpSession session = request.getSession(true);
		session.setAttribute("id", String.valueOf(id));
		String password = "";
		password = request.getParameter("password");

		String kind = "";
		kind = request.getParameter("kind");
		String temp = getPassword(request, responseres, id, kind);
		if (password.equals(temp))
			goo(request, responseres, kind);
		else {
			message = "用户名或密码有误!";
			doError(request, responseres, message);
		}
	}

	public void goo(HttpServletRequest req, HttpServletResponse res, String kind)
			throws ServletException, IOException {

		if (kind.equals("student")) {
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/student.jsp");
			rd.forward(req, res);
		}
		if (kind.equals("teacher")) {
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/teacher.jsp");
			rd.forward(req, res);
		}
		if (kind.equals("admin")) {
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/admin.jsp");
			rd.forward(req, res);
		}
	}

	public String getPassword(HttpServletRequest req, HttpServletResponse res,
			String id, String kind) throws ServletException, IOException {
		sqlBean db = new sqlBean();
		String pw = "";
		String sql = "select password from " + kind + " where name='" + id + "'";
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				pw = rs.getString("password");
			}
		} catch (Exception e) {
			System.out.print(e.toString());
		}
		return pw;
	}

	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 void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String action =  request.getParameter("action");
		if ("logout".equalsIgnoreCase(action)) {
			HttpSession session = request.getSession(true);
			session.invalidate();
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/login.jsp");
			rd.forward(request, response);
		}
	}

}

⌨️ 快捷键说明

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