• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Explain Scope

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anyone please explain me regarding scope of variables and object in a jsp file.
I am getting confused.
Regards
Tejas
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tejas!
When your jsp file is being converted into a servlet the jsp container puts all the code from the expressions, scriptlets and html in a service method called _jspService(). This method then talks to the service method of the created servlet. To understand this you need a basic understanding for how servlets work.
This implies that all the variables being declared in scriptlets in a jsp file, are put into the same _jspService() method in the created servlet, and therefor they are local to that method. This also means that a variable that has been declared in a scriptlet in a jsp file, will be reachable from all the other scriptlets and expressions in the same file.
If you need a global variable, then you should use declarations instead. Because when you declare a variable in a declaration, that variable will be put outside the _jspService() method and will therefor be global in this entire servlet.
Hope this was helpful for you.
Regards
------------------
Dominic Steng�rd
Sun Certified Java 2 Programmer
------------------

[This message has been edited by Dominic Steng�rd (edited May 30, 2001).]
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An excellent way of learning the how and why of implicit objects in JSP is to view the java source file of the servlet (the one that gets made by translating your JSP).

That's how I learned where request, response, application, etc... came from. It is also useful to see the scope of variables you define in scriplets and declaration tags.
 
reply
    Bookmark Topic Watch Topic
  • New Topic