我想从控制器方法获取会话值到jsp。有人可以帮助我如何做到这一点
controller.java
@RequestMapping(value="customerLogin.do", method=RequestMethod.POST)
public String customerLogin(HttpServletRequest request, HttpSession session,HttpServletResponse response) throws SQLException, IOException{
String customerEmail=request.getParameter("customerEmail");
String password= request.getParameter("customerPassword");
Boolean isLoggedIn=false;
Customer customer= serviceInter.logincustomer(customerEmail, password);
if(customer!=null){
isLoggedIn=true;
}
response.getWriter().write(new Gson().toJson(isLoggedIn));
session.setAttribute("customerInfo", customer);
return null;
}
我需要在这里获得该值
答案 0 :(得分:0)
您可以使用以下声明来获取它:
Customer customer = (Customer) session.getAttribute("customerInfo");
//System.out.println(customer.getFirstName());
答案 1 :(得分:-1)
您如何在JSP中检索? 你得到的错误是什么?
${customerInfo.name}
OR
Customer customer = (Customer) session.getAttribute("customerInfo");
第二个选项:您还可以使Controller成为会话范围。
@Controller
@Scope("session")
public class SessionScopedController