简体   繁体   中英

java- session.getattribute returns null

I have a JSP pages that validate a user when he logs in and I would like to capture and store his username for some other uses. So here is the code when the user logs in:

  String username = request.getParameter("username");
                String password = request.getParameter("password");

session.setAttribute("username", username);

I debug the session value and it does indeed return the correct username value. So right now,I want to access this value from another page to see the username it returns.I call this value like below:

Value:<%= session.getAttribute("username") %>

The value returns is Value:null instead of the username (root). I can't figure out what went wrong. Did I do any mistake?

您是否将属性设置为当前会话,如果不这样使用:

request.getSession(true).setAttribute("username", username);

您是否在将控件转发到您要访问的结果页面之前使会话无效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM