📄 loginservlet.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -