• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp

 
manoj Mahadik
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
In jsp While using bean we use "scope" attribute which indicates the context in which the bean should be made available. There are four possible values: page, request, session, and application.Please explain me about these values in detail.
Bye,
Manoj
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The fourth book from the right above has a succinct explanation of the four scopes.
 
prakash muthu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The following stuf will become useful for you.
with regards
Prakash
Various scope of objects
Objects or variables can be considered of having different levels of scope within the application. The different scopes provided by JSP are
 Application
 Session
 Page
Application : Applications can be thought of as a set of cooperating resources (servlets, applets, image file, or webpages) that share information between them to achieve some end functionality. The information is stored in a shared data-object, which is accessible by any of the resources that belong to the application. An application resource can put information into the shared data-object or retrieve information from that data object
Eg. For example, a Web designer might want to add a counter to a .jsp page to show how many times the page has been accessed. The .jsp page might call a Bean named cbean, display the value of the Bean's counter property, and set the values of the Bean's imageDirectory and imageName properties:
<html>
<USEBEAN NAME="cbean" TYPE = "counter.Counter" LIFESPAN = "application">
<SETONCREATE BEANPROPERTY="imageDirectory" VALUE="/images/counter/">
<SETONCREATE BEANPROPERTY="imageName" VALUE="ocr.gif">
</USEBEAN>
This page has been accessed <DISPLAY PROPERTY="cbean:counter"> times.
</html>
Session : This means that the objects lifetime is the there until the the user session is open with the server. Objects having session lifetime can be accessed across requests by the same user. It ends only when there is a session time out or the user closes the browser.

<html>
<USEBEAN NAME="cpageno" TYPE = "page.Pageno" LIFESPAN = "session">
<SETONCREATE BEANPROPERTY="imageDirectory" VALUE="/images/counter/">
<SETONCREATE BEANPROPERTY="imageName" VALUE="ocr.gif">
</USEBEAN>
Page number <DISPLAY PROPERTY="page.Pageno">
</html>

Page: This means that the objects lifetime limited to a particular page. Once the user navigates away from the page, its value is lost.
<html>
<body>
<USEBEAN NAME=bar TYPE=jsp.beans.LunchSpecial LIFESPAN=page >
<SETONCREATE BEANPROPERTY="soup" VALUE="clam chowder">
<SETONCREATE BEANPROPERTY="dessert" VALUE="lemon meringue pie">
</USEBEAN>
<h1>Welcome to Jake's Emporium!</h1>
<h2>Today's Lunch Special is:</h2>
<p>
<ul>
<li>Hot and tasty <DISPLAY PROPERTY="bar:soup" PLACEHOLDER="tomato"> soup</li>
<li>Hearty <DISPLAY PROPERTY="bar:sandwich" PLACEHOLDER="cheese" > sandwich</li>
<li>Homemade <DISPLAY PROPERTY="bar:dessert" PLACEHOLDER="apple" ></li>
</ul>
</p>
</body>
</html>
 
prakash muthu
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I hope the following pareagraph will clear your doubts
with regards
Prakash
Various scope of objects
Objects or variables can be considered of having different levels of scope within the application. The different scopes provided by JSP are
 Application
 Session
 Page
Application : Applications can be thought of as a set of cooperating resources (servlets, applets, image file, or webpages) that share information between them to achieve some end functionality. The information is stored in a shared data-object, which is accessible by any of the resources that belong to the application. An application resource can put information into the shared data-object or retrieve information from that data object
Eg. For example, a Web designer might want to add a counter to a .jsp page to show how many times the page has been accessed. The .jsp page might call a Bean named cbean, display the value of the Bean's counter property, and set the values of the Bean's imageDirectory and imageName properties:
<html>
<USEBEAN NAME="cbean" TYPE = "counter.Counter" LIFESPAN = "application">
<SETONCREATE BEANPROPERTY="imageDirectory" VALUE="/images/counter/">
<SETONCREATE BEANPROPERTY="imageName" VALUE="ocr.gif">
</USEBEAN>
This page has been accessed <DISPLAY PROPERTY="cbean:counter"> times.
</html>
Session : This means that the objects lifetime is the there until the the user session is open with the server. Objects having session lifetime can be accessed across requests by the same user. It ends only when there is a session time out or the user closes the browser.

<html>
<USEBEAN NAME="cpageno" TYPE = "page.Pageno" LIFESPAN = "session">
<SETONCREATE BEANPROPERTY="imageDirectory" VALUE="/images/counter/">
<SETONCREATE BEANPROPERTY="imageName" VALUE="ocr.gif">
</USEBEAN>
Page number <DISPLAY PROPERTY="page.Pageno">
</html>

Page: This means that the objects lifetime limited to a particular page. Once the user navigates away from the page, its value is lost.
<html>
<body>
<USEBEAN NAME=bar TYPE=jsp.beans.LunchSpecial LIFESPAN=page >
<SETONCREATE BEANPROPERTY="soup" VALUE="clam chowder">
<SETONCREATE BEANPROPERTY="dessert" VALUE="lemon meringue pie">
</USEBEAN>
<h1>Welcome to Jake's Emporium!</h1>
<h2>Today's Lunch Special is:</h2>
<p>
<ul>
<li>Hot and tasty <DISPLAY PROPERTY="bar:soup" PLACEHOLDER="tomato"> soup</li>
<li>Hearty <DISPLAY PROPERTY="bar:sandwich" PLACEHOLDER="cheese" > sandwich</li>
<li>Homemade <DISPLAY PROPERTY="bar:dessert" PLACEHOLDER="apple" ></li>
</ul>
</p>
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic