Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to obtain values from session object in jsp.?  RSS feed

 
Deepa Gowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to obtain values from session object in jsp.?

I created a vo(value object) in servlet and put the values in a session object and forwarded it to a jsp. how do i retrieve from there.?

My servlet code:

HttpSession session = request.getSession();
session.setAttribute("ACCOUNT_VO", accountVO);
RequestDispatcher requestDispatcher = request.getRequestDispatcher("./jsp/personDetail.jsp");
requestDispatcher.forward(request, response);

Corresponding jsp code:
<%@page import ="com.cluster.vo.AccountVO" %>
<html>
<body bgcolor = "pink">
<h2>Welcome</h2>
<% AccountVO accountVO = (AccountVO) session.getAttribute("Account_VO");
%>
<p> Your Name is <%= accountVO.getName()%> and your account number is <%= accountVO.getAccountNo()%>
</p>
</body>
</html>


when i try to execute in browser its showing null pointer exception. can someone please help??
 
Paul Clapham
Sheriff
Posts: 22487
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's much easier in JSTL. You don't have to import classes, you don't have to try to create Java variables. Since the methods you need to call follow standard Java Bean naming, you can use them just like properties in JSTL.

However if it's still 2003 where you are working and you are forced to use scriptlets, then I would recommend using the same name to get the object from the session that you used to put it into the session. You didn't do that.
 
Deepa Gowda
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that was a silly mistake..
thank you so much paul for pointing that out.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!