Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > don't understand with behaviour with tomcat session

Reply
Thread Tools

don't understand with behaviour with tomcat session

 
 
Nikko
Guest
Posts: n/a
 
      04-28-2007
Hi all,
I have got a web application(on tomcat server) in which clients have to
be logged to enter. And I would like to create only new user's session
if user's authentification is successful (login/password correct). So,
normaly the number of users logged = number of tomcat's sessions.
In my webapps, I use a 'AuthenticationFilter' which implement Filter
java Class . When user fill his login and password and click button
'enter', I pass in function 'doFilter '

public class AuthenticationFilter implements Filter
{
public void init(FilterConfig config) throws ServletException {}
public void doFilter(ServletRequest req, ServletResponse
res,FilterChain chain) throws IOException, ServletException
{
HttpSession session =
(HttpServletRequest)req).getSession(false);
//session is null, ok no problem
HttpServletRequest request = (HttpServletRequest)req;
//by casting req to HttpServletRequest, a session is created,
and I don't understand
HttpSession session2 = request.getSession(false);
//and now session2 is not null.
}

public void destroy() {}
}

I don't understand why when I do this : HttpServletRequest request
= (HttpServletRequest)req;
a new session is created, (I verified also in tomcat manager)
Has anybody already dealed with this problem?
I use eclipse too with wtp for debug.
 
Reply With Quote
 
 
 
 
Harry
Guest
Posts: n/a
 
      04-30-2007
Hi,

HttpServletRequest request = (HttpServletRequest) req;
should not do any change to session. As you know, it is just a simple
JAVA syntax casting the variable down the inheritance tree. So the
problem may not happen ONLY in this filter. Will it be something
happening on another thread in a servlet class that creates the
session?

To debug this case, I think the Tomcat Manager cannot reflect the
actual case, because when you see the Tomcat Manager, the whole
request already finishes. I suggest you to debug the code line by
line. Then, you can see whether the session is created before and
after your logic above.

Harry

On Apr 28, 3:21 pm, Nikko <M...@yahoo.fr> wrote:
> Hi all,
> I have got a web application(on tomcat server) in which clients have to
> be logged to enter. And I would like to create only new user's session
> if user's authentification is successful (login/password correct). So,
> normaly the number of users logged = number of tomcat's sessions.
> In my webapps, I use a 'AuthenticationFilter' which implement Filter
> java Class . When user fill his login and password and click button
> 'enter', I pass in function 'doFilter '
>
> public class AuthenticationFilter implements Filter
> {
> public void init(FilterConfig config) throws ServletException {}
> public void doFilter(ServletRequest req, ServletResponse
> res,FilterChain chain) throws IOException, ServletException
> {
> HttpSession session =
> (HttpServletRequest)req).getSession(false);
> //session is null, ok no problem
> HttpServletRequest request = (HttpServletRequest)req;
> //by casting req to HttpServletRequest, a session is created,
> and I don't understand
> HttpSession session2 = request.getSession(false);
> //and now session2 is not null.
> }
>
> public void destroy() {}
>
> }
>
> I don't understand why when I do this : HttpServletRequest request
> = (HttpServletRequest)req;
> a new session is created, (I verified also in tomcat manager)
> Has anybody already dealed with this problem?
> I use eclipse too with wtp for debug.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Behaviour of subprocess.Popen, ssh and nohup I don't understand Kushal Kumaran Python 0 04-01-2011 05:33 AM
don't understand behaviour of recursive structure Dan Davison Python 3 03-14-2009 07:53 PM
Trying to understand rfc822.Message() behaviour Phoe6 Python 4 11-30-2006 06:44 PM
division... strange behaviour i dont understand clqrq@yahoo.de C++ 10 07-12-2006 07:05 PM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM



Advertisments