• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fun with Session variables and scope  RSS feed

 
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: 66154
146
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: 51
  • 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: 66154
146
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!