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

📄 entryservlet.java

📁 运用JSP/servlet/JavaBean 技术
💻 JAVA
字号:
package com.lovo.controller;

import java.io.IOException;
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.lovo.po.User;
import com.lovo.service.IUserBo;
import com.lovo.service.IUserBoImpl;

/**
 * <p>管理登录的控制器</p>
 * @author fenglu
 *
 */
public class EntryServlet extends HttpServlet
{
	/** userBo接口,用于业务方法调用 */
	private IUserBo userBo = new IUserBoImpl();

	/**
	 * 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; charset=utf-8");
		/** 设置响应头,让浏览器不缓存信息 */
		response.setHeader("Cache-control", "no-cache");
		/** 获得登录帐号及密码 */
		String emailName = request.getParameter("emailName").toLowerCase();
		String password  = request.getParameter("password");
		/** 获得session */
		HttpSession session = request.getSession();
		/** 将获得的信息封装到User对象中 */
		User user = new User();
		user.setEmailName(emailName);
		user.setPassword(password);
		/** 检测用户信息是否匹配 */
		User tempUser = userBo.checkUser(user);
		/**
		 * 如果passCheck为true则用户匹配,可以登录QQMail
		 * 如果passCheck为false则不匹配,不能登录,返回Entry.html页面
		 */
		if(tempUser != null)
		{
			/** 用户匹配,添加到session */
			session.setAttribute("user", tempUser);
			/** 登录邮箱主页面QQMail.html */
			response.sendRedirect("QQMail.html");
		}
		else
		{
			/** 用户不匹配,设置反馈信息 */
			session.setAttribute("entryMsg", "用户或密码错误,请重新输入!");
			/** 登录失败,跳转到Entry.html重新登录 */
			response.sendRedirect("Entry.html");
		}
	}

	/**
	 * 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);
	}

}

⌨️ 快捷键说明

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