Unable to get session in Java servlet

I am using servlets for the first time, but I have made great progress. My servlets work well. So I decided to put in an authentication mechanism that creates a session if users give the correct password and identifiers. But the sessions are completely new to me. Therefore, I do not quite understand the logic, but I began to understand.

As I mentioned earlier, one of my servlets is for logging in. If the password is correct, a session is created (I do not store any object / data in the sessions), and the client (remoteUser) is notified that the password has been accepted and the session. What the client does is access to any other servlet in one application. Other servlets receive a session to check if it is created and valid (not installed). For this purpose, in these other servlets, I get a session with:

HttpSession session = req.getSession(false); //false because this is not the place to create a session. sessions should only be created in the login servlet. 

But this returns zero. So I tried:

 HttpSession session = req.getSession(); 

And checked with session.isNew (); and I had a new session. So the session that I created in the login server cannot be called with req.getSession (); in another servlet.

PS: When a session is created in the login servlet: session.setMaxInactiveInterval (300); // 5 minutes

Thanks so much for any answer!

+6
source share
1 answer

When using the Google App Engine, you need to specifically enable session support. See http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions .

+5
source

Source: https://habr.com/ru/post/893865/


All Articles