validate.java

来自「网上商店代码」· Java 代码 · 共 107 行

JAVA
107
字号
package com.ata.shoping.servlet;
/*
 * 用户身份的验证
 * 若为管理员用户登录管理员页面
 * 若为用户登录用户页面
 * 若所输入的用户名和密码有错,返回首页
 */
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.*;
import com.projiect.shopping.sql.*;





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

	/**
	 * Constructor of the object.
	 */
	public Validate() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * 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 {

		response.setContentType("text/html");
		response.setCharacterEncoding("gbk");
		HttpSession session = request.getSession();
		String userName = request.getParameter("username");
		String password = request.getParameter("password");
		PrintWriter out = response.getWriter();
//		out.print(userName+"  "+password);
		UserInfo userinfo = new UserInfo();
		userinfo.setUserName(userName);
		userinfo.setPassword(password);
	
		if(JdbcOperation.IsUserinfoExist(userinfo)){
				session.setAttribute("enterUser", userinfo);
				
				if(userName.equals("admin")){
					//管理员用户登录
					session.setAttribute("username", userName);
					response.sendRedirect("/Shopping/Login.jsp");
				}else{
					//消费用户登录
					session.setAttribute("username", userName);
					response.sendRedirect("/Shopping/home.jsp");
				}
		}
		else
		{//登录出错
			response.sendRedirect("/Shopping/index.jsp?err=errin");
		}
		
	}

	/**
	 * 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 {

		doGet(request,response);
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

⌨️ 快捷键说明

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