开发者

Using Session in Struts and JSP

开发者 https://www.devze.com 2023-03-14 13:09 出处:网络
I am new to Struts so I have a simple question.On LoginAction.java I have used the following, HttpSession session = request.getSession(true);

I am new to Struts so I have a simple question. On LoginAction.java I have used the following,

HttpSession session = request.getSession(true);
...
...
session.setAttribute(authuser.getSess_userid(), "userid");
session.setAttribute(authuser.getSess_username(), "u开发者_开发技巧sername");
session.setAttribute(authuser.getSess_access(), "usertype");
return mapping.findForward(SUCCESS);
...
...

And on welcome.jsp,

<p> <bean:message key="title.welcome_en" /> <%=session.getAttribute("username").toString()%> </p>

However, I am getting NullPointException on welcome.jsp. What am I doing wrong???

Thank you.


It should be

session.setAttribute("userid", authuser.getSess_userid());
session.setAttribute("username", authuser.getSess_username());
session.setAttribute( "usertype", authuser.getSess_access());

http://download.oracle.com/javaee/5/api/javax/servlet/http/HttpSession.html#setAttribute(java.lang.String, java.lang.Object)

0

精彩评论

暂无评论...
验证码 换一张
取 消