I have a application running on tomcat server , which is redirected to another website for password authentication ( and store some data) , and then redirected back to my tomcat server
EX
1 to A
A to B
B to 2
Where 1 and 2 are pages on my application
A and B are pages on other applications
I am setting a session variable on my page 1 using
HttpSession session = request.getSession(true);
session.setAttribute("loginUser", "loginUser");
and using it on page 2 using
String loginUser= session.getAttribute("loginUser");
but getting a null pointer exception on 2
If you’re doing a redirect in the same context (Application), rather use
RequestDispatcherto do aforward(passing yourrequestandresponse). That way, you pass your session through.Otherwise, my suggestion is to not store the
loginUseron the session but pass user id variable as some intelligent (and confused) string to the other application, write a mechanism to retrieve the user logged in session state and carry on from there. This is called, Single-Sign On.