loginservlet.java

来自「网上书城源代码~~在学习JAVA的时候做的」· Java 代码 · 共 44 行

JAVA
44
字号
package com.briup.servlet;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.briup.bean.Customer;import com.briup.common.BeanFactory;import com.briup.common.exception.CustomerServiceException;import com.briup.service.ICustomerService;@SuppressWarnings("serial")public class LoginServlet extends HttpServlet {	private ICustomerService customerService;	public void init(){		customerService=(ICustomerService) BeanFactory.getBean(BeanFactory.CUSTOMERSERVICE);	}	public void doGet(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		doPost(request,response);	}	public void doPost(HttpServletRequest request, HttpServletResponse response)			throws ServletException, IOException {		String name=request.getParameter("name");		String password=request.getParameter("password");		Customer customer=null;		try {			customer=customerService.login(name, password);			HttpSession session=request.getSession();			session.setAttribute("customer", customer);			response.sendRedirect(request.getContextPath()+"/listBookStore.jsp");		} catch (CustomerServiceException e) {			e.printStackTrace();			request.setAttribute("error", e.getMessage());			request.getRequestDispatcher("/login.jsp").forward(request, response);		}	}}

⌨️ 快捷键说明

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