Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Fun with Session variables and scope

 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way I can make functions that do this:



I get errors:

Generated servlet error:
session cannot be resolved


Doing this would allow me to have procedures do all the work and not worry about a thing....

or...

can session objects be accessed inside java beans

thanks

James
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The session implicit variable is only in scope inside the service method of your JSP. It is not available to declarations.

The best way to understand this is to take a look at the .java file that the container creates on behalf of your JSP.

If you want to reference the session from declared methods (shudder), or within Javabeans, you need to explicitly pass it (or the request, from which you can obtain the session).
[ May 13, 2005: Message edited by: Bear Bibeault ]
 
Adrian Enns
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you not just pass the session object into the declared functions? For example:

<%
out.println(getVar(session));
setVar(session);
%>

<%!
void setVar(HttpSession aSession)
{
aSession.setAttribute( "hombre", "jolly");
}

String getVar(HttpSession aSession)
{
String x = (String)aSession.getAttribute( "hombre" );
return (x==null)?"arg":x;
}
%>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read paragraph 3.
 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome!

That worked...

Just what I was looking for


thanks so much

James
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!