求解jsp连接MySQL登录成功后,可以在多个jsp页面都获取当前登录的用户账号吗??
求解:jsp连接MySQL登录成功后,可以在多个jsp页面都获取当前登录的用户账号吗??应该如何是实现???
尝试过使用session,javabean获取当前用户,但是都只有一个showMessEnterprise.jsp可以获取,其他的jsp页面都是null.
servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
String enterpriseid=request.getParameter("enterpriseid");
String password=request.getParameter("password");
Enterprise enterprise=new Enterprise(enterpriseid,password);
EnterpriseService enterpriseService=new EnterpriseServiceImpl();
//one
//HttpSession session=request.getSession(true);
//session.setAttribute("enterprise", enterprise);
//
request.setAttribute("enterpriseid",enterpriseid);
if(enterpriseService.loginenterprise(enterprise)!=null) {
RequestDispatcher dispathcher=request.getRequestDispatcher("showMessEnterprise.jsp");
dispathcher.forward(request, response);
}else {
response.sendRedirect("loginEnterprise.jsp");
}
}
jsp
<%=request.getAttribute("enterpriseid")%>