Sourav Bag
Sourav Bag

Reputation: 359

session.getAttribute not returning the correct value

In one of my application i've set one variable (String) in a session. The detail code is below in one of my servlet.

HttpSession session = request.getSession();
String val1 = "http://abc.gmail.com/pp/hello.do?supplierId=894";
session.setAttribute("val1", val1);

Now i retrieved the value of the session attribute in one jsp by the below code.

<%
String val1 = (String) session.getAttribute("val1");
System.out.println("The value is-->>"+val1);
%>

But it's printing only "http://abc.gmail.com/pp/hello.do?supplierId"

Could you please help me fixing this error. I'm expecting the o/p to be "http://abc.gmail.com/pp/hello.do?supplierId=894"

Thanks, Sourav

Upvotes: 0

Views: 2059

Answers (2)

Aaron Digulla
Aaron Digulla

Reputation: 328556

There are two possible reasons for this:

  1. Somewhere else in the code, the value is overwritten
  2. You stripped too much code when you posted the example.

To find out which is which, you can:

  1. Add a System.out.println() right after session.setAttribute() to see the value that is actually put into the session.
  2. Create a filter that prints the value before and after each request. This will help you narrow down where it is modified.
  3. Set a breakpoint in the implementation of session.setAttribute(). Might not be feasible when thousands of attributes are set.

Upvotes: 1

user756706
user756706

Reputation:

I think you have problem with =

try following

  1. convert string in base64, put it in session
  2. get string from session , convert base64 to normal

I should work

Upvotes: 0

Related Questions