首页>代码>JSP开发企业办公自动化管理系统源代码下载>/备忘录模块/12/src/com/action/UserServlet.java
package com.action;

import java.io.IOException;
import java.io.PrintWriter;

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.dao.UserDAO;
import com.model.UserForm;
import com.tools.StringUtils;

public class UserServlet extends HttpServlet {
	private UserDAO userDAO = new UserDAO();

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

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

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

		String action = request.getParameter("action");
		if ("login".equals(action)) {
			this.login(request, response); // 用户登录
		} 
	}

	public void login(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=GBK");
		StringUtils su = new StringUtils();
		UserForm f = new UserForm();
		f.setUserName(su.toGBK(request.getParameter("userName"))); // 获取并设置用户名
		f.setPwd(request.getParameter("pwd")); // 获取并设置密码
		int r = userDAO.login(f);
		if (r == 1) {
			HttpSession session = request.getSession();
			session.setAttribute("userName", f.getUserName());
			request.getRequestDispatcher("login_ok.jsp").forward(request,
					response);
		} else {
			request.setAttribute("error", "您输入的用户名或密码错误!");
			request.getRequestDispatcher("error.jsp")
					.forward(request, response);
		}

	}



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

}
最近下载更多
ming_123_9715  LV23 2023年3月6日
dasdascccf  LV10 2022年6月16日
eniu_27  LV5 2022年5月30日
jinglang  LV11 2022年5月8日
Start1  LV15 2021年10月30日
天66666  LV6 2021年5月30日
Hitomi1  LV2 2021年5月26日
freeblow  LV2 2021年5月20日
nitama  LV19 2021年5月14日
晚春的树和书  LV6 2021年4月30日
最近浏览更多
pangzhihui  LV12 3月1日
晴曛  LV6 2月20日
123456wadff  LV3 1月15日
WBelong  LV7 2023年12月27日
asddwh  LV12 2023年12月26日
hxy19991216  LV4 2023年12月23日
Henew168  LV2 2023年11月19日
2749263182 2023年11月12日
暂无贡献等级
dsadasdwf  LV12 2023年10月23日
fesfefe  LV13 2023年10月10日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友