开发者

Can't get the session in java servlet

I am using servlets for the first time but I made a lot of progress. My servlets are working well. So I decided to put an authentication mechanism, which creates a session, if users give the right password and id's. But sessions are totally new for me. So I don't quite follow the logic but I have started to understand.

As I mentioned before one of my servlets is dedicated for logging in. If password is correct a session is created (I don't store any object/data in sessions) and client (remoteUser) is notified that the password is accepted and session is created. What client does is to reach any other servlet in the same application. Other servlets开发者_JS百科 get the session to check if it is created and valid (not timed out). For that purpose in those other servlets I get the 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 a null. So I have tried:

HttpSession session = req.getSession();

And checked with session.isNew(); and I it was a new session. So the session I have created in login servlet can't be called with req.getSession(); in another servlet.

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

Thanks a lot for any response!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜