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.

i could be wrong but i think u have to use session.getAttribute

I tried with session.getAttribute("username")

Still type incompatible .. Plz help

can u post your code, because i tried it and it works perfectly.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.