JSP Introduction
Simple JSP(Example-1)
JSP Err.Pag.(Example-2)
JavaBeans in JSP
JavaBeans(Example-3)
JSP Custom Tags
CustomTag(Example-4)
Design Patterns
Design Patt.(Example-5)
Bookmark This Site
|
Using JavaBeans in JSP
Introduction
|
JAVABEANS components are Java classes that can be easily reused and composed together into applications. Any Java class that follows certain design conventions can be a JavaBeans component.
|
|
Including Bean Reference
|
-
The following code snippet shows the syntax of the <jsp:useBean> action tag:
-
<jsp:useBean id="Bean Name" scope="ScopeName" class="class name />
A JavaBean can exist in the following scopes:-
page: Specifies that the JavaBean object is available for the current page only. This is the default scope of a JavaBean.
-
<jsp:useBean id="option_bean" scope ="page" class="test.OptionBean"/>
-
test.OptionBean option_bean=new test.OptionBean();
-
request: Specifies that the JavaBean object is available for the current request.
-
<jsp:useBean id="option_bean" scope ="request" class="test.OptionBean"/>
-
test.OptionBean option_bean=new test.OptionBean();
request.setAttribute("option_bean ", option_bean);
-
session: Specifies that the JavaBean object is available for the current session only.
-
<jsp:useBean id="option_bean" scope ="session" class="test.OptionBean"/>
-
HttpSession session = request.getSession(true);
test.OptionBean option_bean=new test.OptionBean();
session.setAttribute("option_bean ", option_bean);
-
application: Specifies that the JavaBean object is available for the entire Web application.
-
<jsp:useBean id="option_bean" scope ="application" class="test.OptionBean" />
-
test.OptionBean option_bean=new test.OptionBean();
getServletContext().setAttribute("option_bean ", option_bean);
|
Setting Beans Properties
|
- The following syntax shows how to set a property of a JavaBean using <jsp:setProperty> tag:
<jsp:setProperty name="beanName" property=" propertyName">
|
Reading Bean Properties
|
- The following syntax shows how to get the JavaBean property using <jsp:getProperty> tag:
<jsp:getProperty name="beanName" property="propertyName" />
|
|
Click for Next Topic
|
|
|