0

I tried to store session using..
String UserId=request.getParameter("username");
session.setAttribute("username", UserId);


and when I try to access it in some other jsp/servlet using

request.getAttribute("username")

it is showing incompatible data types and showing value null..

but request.getParameter(); is working fine .. wht to do if I need to access this variable in some other JSP.. Plz help..!

Thx a lot in advance.

3
Contributors
4
Replies
6
Views
9 Years
Discussion Span
Last Post by pm4
0

I tried with session.getAttribute("username")

Still type incompatible .. Plz help

0

you should type your code almost such this:

String userID=request.getAttribute("username");
HttpSession session=request.getSession(true);
session.setAttribute("username",userID);

when you want to access it in some other jsp/servlet page type this:

-- another page ---

HttpSession session=request.getSession();

String username= (String) session.getAttribute("username");

---------------------------------------------------------------------------
you can not use request.getAttribute("username") in another page if you haven't used any request.setAttribute("username", any_value) to keep a value.
good lock friend.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.