You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Andoni <an...@indigo.ie> on 2003/11/17 16:23:09 UTC

Can I find out if there is an active session from my JSP?

Hello,

I have recently moved my web-app to Form-based container managed logins.

I like very much the side effect that this has which is that if you go off to another site and come back you are not given the login screen again.

What worries me is people who will bookmark the login screen, I would like to be able to check if they have an existing session and if so then forward them to the next .jsp (the main menu).  Unfortunately the login screen is a .jsp so it automatically creates a new session if there is not already one in existence.  Is there any way to stop it doing this?

My thanks in advance as ever,

Andoni.

Re: Can I find out if there is an active session from my JSP?

Posted by Andoni <an...@indigo.ie>.
Sorry, just found this in the page directive

<%@ page session=false %>

I assume it will solve my problems.

Thanks,
Andoni.


----- Original Message -----
From: "Andoni" <an...@indigo.ie>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, November 17, 2003 3:23 PM
Subject: Can I find out if there is an active session from my JSP?


Hello,

I have recently moved my web-app to Form-based container managed logins.

I like very much the side effect that this has which is that if you go off
to another site and come back you are not given the login screen again.

What worries me is people who will bookmark the login screen, I would like
to be able to check if they have an existing session and if so then forward
them to the next .jsp (the main menu).  Unfortunately the login screen is a
.jsp so it automatically creates a new session if there is not already one
in existence.  Is there any way to stop it doing this?

My thanks in advance as ever,

Andoni.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Can I find out if there is an active session from my JSP?

Posted by Christopher Schultz <ch...@comcast.net>.
Andoni,
> On reading more closely I find that this directive does not allow me to use
> sessions at all.

> This does not wok as the "off-switch" in the <%@page part is permanent.
> 
> <%@ page
>  session="false"
> %><%
> 
> // If this user has an active session... USE IT!
> if(null != request.getSession(false))
> {
>  response.sendRedirect("myMainMenu.jsp");
> }
> else
> {
>  request.getSession();
> }
> %>

You can still use the session, it's just not declared for you. You have 
to do this:

<%@page session="false"
	import="javax.servlet.http.HttpSession"
%>
<%
	HttpSession session = request.getSession(false);

	if(null == session)
		// Do something
	else
		// Do something else
%>

-chris


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Can I find out if there is an active session from my JSP?

Posted by Andoni <an...@indigo.ie>.
On reading more closely I find that this directive does not allow me to use
sessions at all.

What I want is to be able to turn them off to start, or at least not create
a new one if there is one in existence already, then turn them on when I
need them.

See if this bit of code helps explain what I mean:

This does not wok as the "off-switch" in the <%@page part is permanent.

<%@ page
 session="false"
%><%

// If this user has an active session... USE IT!
if(null != request.getSession(false))
{
 response.sendRedirect("myMainMenu.jsp");
}
else
{
 request.getSession();
}
%>



----- Original Message -----
From: "Harry Mantheakis" <ha...@mantheakis.freeserve.co.uk>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, November 17, 2003 3:24 PM
Subject: Re: Can I find out if there is an active session from my JSP?


> Hello
>
> > What worries me is people who will bookmark the login screen, I would
like to
> > be able to check if they have an existing session and if so then forward
them
> > to the next .jsp (the main menu).  Unfortunately the login screen is a
.jsp so
> > it automatically creates a new session if there is not already one in
> > existence.  Is there any way to stop it doing this?
>
> Set the 'session' page directive to false:
>
> <%@page session="false" %>
>
> Regards
>
> Harry Mantheakis
> London, UK
>
>
> > Hello,
> >
> > I have recently moved my web-app to Form-based container managed logins.
> >
> > I like very much the side effect that this has which is that if you go
off to
> > another site and come back you are not given the login screen again.
> >
> > What worries me is people who will bookmark the login screen, I would
like to
> > be able to check if they have an existing session and if so then forward
them
> > to the next .jsp (the main menu).  Unfortunately the login screen is a
.jsp so
> > it automatically creates a new session if there is not already one in
> > existence.  Is there any way to stop it doing this?
> >
> > My thanks in advance as ever,
> >
> > Andoni.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Can I find out if there is an active session from my JSP?

Posted by Harry Mantheakis <ha...@mantheakis.freeserve.co.uk>.
Hello

> What worries me is people who will bookmark the login screen, I would like to
> be able to check if they have an existing session and if so then forward them
> to the next .jsp (the main menu).  Unfortunately the login screen is a .jsp so
> it automatically creates a new session if there is not already one in
> existence.  Is there any way to stop it doing this?

Set the 'session' page directive to false:

<%@page session="false" %>

Regards

Harry Mantheakis
London, UK


> Hello,
> 
> I have recently moved my web-app to Form-based container managed logins.
> 
> I like very much the side effect that this has which is that if you go off to
> another site and come back you are not given the login screen again.
> 
> What worries me is people who will bookmark the login screen, I would like to
> be able to check if they have an existing session and if so then forward them
> to the next .jsp (the main menu).  Unfortunately the login screen is a .jsp so
> it automatically creates a new session if there is not already one in
> existence.  Is there any way to stop it doing this?
> 
> My thanks in advance as ever,
> 
> Andoni.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org