开发者

Using Session in Struts and JSP

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜