Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Using Beans And Page Scope 
 

The scope in which the Bean exists and the variable named in id is available. The default value of scope is page.

 

Using Beans And Page Scope

                          

The scope in which the Bean exists and the variable named in id is available. The  default value of scope is page. In this bean object is placed in the PageContext object for the duration of the current request  

  1. page: It is a default value of scope. In this bean object is placed in the PageContext object and the object can be accessed within the page only.

<jsp:useBean>: This standard tag builds a new bean. It builds a object of the Bean class.
The syntax is <jsp:useBean id = "beanInstance" class = "package.className"/>

<jsp:setProperty>: This tag is used to modify the bean property. It calls the setXXX() method of the bean class.
The syntax is <jsp:setProperty name = "beanInstance" property = "propertyName" value = "propertyValue"/>.

<jsp:getProperty>: This tag is used to read and display the value of a bean property.
The syntax is <jsp:getProperty name = "beanInstance" property = "propertyName" />

The code of the program is given below:

 

package Mybean;
public class UsingBeanScopePage{
  private static int counter = 0;
  public void setCounter(int counter) {
    this.counter = counter;
  }
  public int getCounter(){
    return counter;
  }
}

 

<html>
  <head>
    <title>Using Beans and Page Scope</title>
  </head>
  <body>
    <h1>Using Beans and Page Scope</h1>
    <jsp:useBean id="pageScopeBean" class="Mybean.UsingBeanScopePage" scope="page" />
    <% 
    pageScopeBean.setCounter(pageScopeBean.getCounter() + 1);
    %>
	Counter value is <%= pageScopeBean.getCounter() %>
  </body>
</html>

The output of the program is given below:

Download this example.

                          

» View all related tutorials
Related Tags: c stl orm text form parameters attributes io servlet initialization header format request headers parameter attribute context response ai tex

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.