Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Fun with Session variables and scope

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read paragraph 3.
 
icredes
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
awesome!

That worked...

Just what I was looking for


thanks so much

James
reply
    Bookmark Topic Watch Topic
  • New Topic