login.java

来自「用jsp+servlet」· Java 代码 · 共 73 行

JAVA
73
字号
package server;



import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;


public class Login 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 {
		doPost(request,response);
	}

	/**
	 * 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 {
		DBConnection db = new DBConnection();
		HttpSession session =request.getSession();
		String username = request.getParameter("username");
		String pin = request.getParameter("password");
		db.executeQuery("select * from atm where accountnumber="+username+" and pin="+pin);
		if(!db.rs_next()) {
			session.setAttribute("status", "failed");
			response.sendRedirect("index.jsp");
		}else {
			session.setAttribute("accountnumber", username);
			session.setAttribute("pin", pin);
			session.setAttribute("username", username);
			response.sendRedirect("welcome.jsp");
		}
	}

	/**
	 * The doPut method of the servlet. <br>
	 *
	 * This method is called when a HTTP put request is received.
	 * 
	 * @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 doPut(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		// Put your code here
	}

}

⌨️ 快捷键说明

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