check1.java

来自「比较简单学生查询系统」· Java 代码 · 共 58 行

JAVA
58
字号
package com.fi;

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

public class Check1 extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		doPost(req, res);

	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		res.setCharacterEncoding("UTF-8");
		req.setCharacterEncoding("GBK");
		String username ="";
		String password ="";
		username = req.getParameter("username").trim();
		System.out.print("username"+username);
		HttpSession session = req.getSession(true);//?
		session.setAttribute("name",username);
		password = req.getParameter("password").trim();
		// res.getWriter().print("password"+password);
		String temp = getPassword(username);
		if ((password.trim()).equals(temp.trim()))

		{
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/success.jsp");
			rd.forward(req, res);
		} else {
			RequestDispatcher rd = getServletContext().getRequestDispatcher(
					"/errors.jsp");
			rd.forward(req, res);
		}
	}

	public String getPassword(String username) {
		sqlBean db = new sqlBean();
		String pw = "";
		String sql = "select password from userinfo where username='"
				+ username + "'";
		try {
			ResultSet rs = db.executeQuery(sql);
			if (rs.next()) {
				pw = rs.getString("password");
				
			}
		} catch (Exception e) {
			
		}
		return pw;
	}
}

⌨️ 快捷键说明

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