Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain Scope

 
Tejas Kansara
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
 
Dominic Steng�rd
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • 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).]
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic