我在登陆的时候用一个action设置了
s_user = (String)s.getAttribute("current_user");
if( s_user == null ){
s.setAttribute("current_user",username);
return (map.findForward("login"));
}else{
//设置当前用户
s.removeAttribute("current_user");
s.setAttribute("current_user",username);
return (map.findForward("login"));
}
然后在在其他页面和action中获取当前用户值
<%=request.getSession().getAttribute("current_user") %>
或者action中
HttpSession s = request.getSession();
String userZh = (String)s.getAttribute("current_user");
都是空值,有那些原因导致了获取得到NULL。请高手指教十分感谢!!!
s_user = (String)s.getAttribute("current_user");
if( s_user == null ){
s.setAttribute("current_user",username);
return (map.findForward("login"));
}else{
//设置当前用户
s.removeAttribute("current_user");
s.setAttribute("current_user",username);
return (map.findForward("login"));
}
然后在在其他页面和action中获取当前用户值
<%=request.getSession().getAttribute("current_user") %>
或者action中
HttpSession s = request.getSession();
String userZh = (String)s.getAttribute("current_user");
都是空值,有那些原因导致了获取得到NULL。请高手指教十分感谢!!!
能解释下这么用的吗
怀疑是你的Username变量的作用域有问题
直接在setAttribute的时候就给定一个值,看看能不能get。邪门了
String password = null;
String s_user = null;
username = (String)((UserBean)form).getUserName();
password = (String)((UserBean)form).getPassWord();
就是从登陆框中获取的账号,密码,保存在一个bean里,再在这里获取。登陆都严重成功了,这个变量应该是没问题的
没看出问题来,多整点代码
<%=request.getSession().getAttribute("current_user") %>
这样错了。改成
<%
String user = (String)session.getAttribute("current_user");
%>
<%=user %>
就可以了。邪门了。哪位高手解释下呀。在bean中的
HttpSession s = request.getSession();
String userZh = (String)s.getAttribute("current_user");
又要怎么改才对呢??!!
吃饭去先,晚上回来结贴!谢谢各位热心大哥的支持。我代表菜鸟们衷心感谢下。
这里已经通过bean赋值了,不是这里的问题。
结贴了,谢谢大家!