*
The moose likes JSP and the fly likes Session var set in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Session var set in JSP " Watch "Session var set in JSP " New topic
Author

Session var set in JSP

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
Hi all,
I have set a session, application var. in a JSP as follows:
<%
..
session.setAttribute("debugmode",String.valueOf(debugmode));
getServletContext().setAttribute("log",log);
..
%>
then this JSP will call a Servlet and from that Servlet I am try to use those session, application var. as follows:

HttpSession session = request.getSession(false);
Boolean tmpb = new Boolean((String)session.getAttribute("debugmode"));
BufferedWriter log = (BufferedWriter)getServletContext().getAttribute("log")

Which is nothing complicated but both values are null when I try to retriev them from the Servlet.
Can someone shed some light on this?
Thanks

Sean <br />SCJP2, SCJP2p1.4, SCWCD
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Seems like a silly thing to ask, but both 'debugmode' and 'log' are variables that are in scope when you place them into the session and application contexts in your JSP?

sean cee
Ranch Hand

Joined: Oct 24, 2000
Posts: 115
yes.
and within that JSP I can look up those attributes as well.
Ganga Ch
Greenhorn

Joined: Nov 15, 2001
Posts: 1
HttpSession session = request.getSession(false);
Boolean tmpb = new Boolean((String)session.getAttribute("debugmode"));
BufferedWriter log = (BufferedWriter)getServletContext().getAttribute("log")
Hi, you might have found the solution, but dont you have to set the session to "true" when you "getSession".
-G
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Maybe -- maybe not. The difference between getSession(true) and getSession(false) is that getSession(false) will return null instead of an HttpSession object if a session has not yet been established (with getSession(true)) for that user...
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session var set in JSP