1

I have a servlet which have these values and I want to pass these values to the java class in session attribute. How can I access these session attributes because I am not using JSF or Struts. This is simple Java Web application.

userID=map.get("UserID");

log.debug("The UserID in case of CCM authtication are : "+userID);

session.setAttribute("UserID", userID);
String refSys="";
refSys = map.get("refSystem");
log.debug("The refSystem in case of CCM authtication is: "+refSys);
session.setAttribute("refSystem", refSys);

This is how I am trying to get in the Java class and I am getting null in the Java class.

HttpSession session = null;

session.getAttribute("UserID");
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
user3548196
  • 355
  • 1
  • 9
  • 32

2 Answers2

-1

Well, your session only can be null, because you don't initialize it. You have to do something like that first to initialize the HttpSession-object:

HttpSession s = request.getSession();

After that you can access your userId via the HttpSession.

Christian
  • 22,585
  • 9
  • 80
  • 106
-1

you are intially setting your session to null.

change ur code to this :

HttpSession session = null;
HttpSession session = request.getSession();
String userId =session.getAttribute("UserID");

hope it works !!

Subham Tripathi
  • 2,683
  • 6
  • 41
  • 70