• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

JSP; Servlets; html: How do I retreave a value from a session object into a JSP?

One of my servlets, Address.java binds a value to a session object:
       HttpSession session = request.getSession(true);
      session.setAttribute("location", lcn);

Then I have a JSP to display a table, but the value is not retrieved from the session object.

FOR EXAMPLE, the following does not work:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page session="true"%>

<html>
<body>
<center>
<table cellpadding=4 cellspacing=2 border=0>
 
<th bgcolor="#CCCCFF" colspan=3>
<font size=4>THE LOCATION</font>
<br>
<br>
</th>

<tr bgcolor="#c8d8f8">
<td valign=top>
<b>Location</b>
<br><br>
<% String location = (String) session.getAttribute("location"); %>

What am I missing in the above four lines to make them work?
I get no error message. The table displays but without the value of location. I'd appreciate your instruction.
0
Rrugemalira
Asked:
Rrugemalira
  • 4
2 Solutions
 
sudhakar_koundinyaCommented:
is servlet called before JSP execution??
0
 
sudhakar_koundinyaCommented:
HttpSession session = request.getSession(true);
     session.setAttribute("location", lcn);
System.err.println(lcn);  //test this whether u r getting right value here itself
0
 
RrugemaliraAuthor Commented:
I've discovered I had to add one line <%= location %> to have the following that works:

                     <tr bgcolor="#c8d8f8">
                     <td valign=top>
                     <b>Location</b>
                     <br><br>
                     <% String location = (String) session.getAttribute("location"); %>
                     <%= location %>
Thanks
0
 
sudhakar_koundinyaCommented:
ok

u can close the question now

ask community support people for help
0
 
sudhakar_koundinyaCommented:
I should say great theanks to you.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now