Tutorial Home
Hibernate
-
Advantage of Hibernate over JDBC
- Hibernate Setup with an web Application
- First Hibernate Application
- Hibernate mapping with Database TABLE
- Hibernate Data Type-Java Data Type - SQL Data Type mapping
- One to Many Relation in Hibernate
- One to Many Relation in Hibernate bi-directional
- Many to Many Relation in Hibernate
- HQL: The Hibernate Query Language
- Criteria Queries
- Criteria Queries : Equal (eq), Not Equal(ne), Less than (le), greater than (gt),greater than or equal(ge) and Ordering the results
- Criteria Queries: And OR conditions
- Hibernate generator to generate id (primary key)
- prevent concurrent update in Hibernate,slate object updatation in Hibernate,version checking in Hibernate
Struts
- Model View Controller (MVC)
- Model View Controller (MVC)
- Struts Flow-How Struts Works?
- Struts Tutorial - Struts Setup- First Struts Action class setup
- Message Resources
- Validation Framework
- Validation Framework-client side
- ForwardAction
- IncludeAction
- DispatchAction
- LookupDispatchAction
- DynaActionForm
- DynaActionForm
- Struts Tutorial - Mutli-click prevention using struts tokens-Prevent Duplicate Submission
- Logic Iterate Map and List
JSP
- JSP Tutorial
- Introduction to JSP
- JSP Comments
- JSP Syntax
- JSP Scripting Elements :Scriptlet, expression, declaration
- JSP Directives
- implicit objects in JSP
- JSP Actions
- Introduction to JSP
- jsp:useBean
- The jsp:setProperty Action
- The jsp:getProperty Action
- Introduction to JSP
Spring
- Spring Tutorial
- Introduction to Spring
- Benefits of Using Spring Framework
- Inversion of Control in Spring
- Introduction to BeanFactory
- Dependency Injection in Spring
- Collections Setter Injection
- Bean Scopes in Spring
- Spring IOC Setup Step by Step
- Bean Lifecycle in Spring
- ApplicationContext
- MessageSources in Spring
- Web Spring MVC framework
- Developing Your First Spring Web Application
- Developing Your Second Spring Web Application with Spring Form
- Developing Your First Spring Web Application with Spring Validation Framework with Code Example
- Spring integration with Hibernate
|
jsp:useBean
The jsp:useBean Action
This action load in a JavaBean to be used in the JSP page.
The simplest syntax for specifying
that a bean should be used is:
<jsp:useBean id="name" class="package.class" />
This usually means "instantiate an object of the class specified by class,
and bind it to a variable with the name specified by id." You can specify a scope attribute that makes the bean associated with more than just the current page. In that case, it is useful
to obtain references to existing beans, and the jsp:useBean action specifies
that a new object is instantiated only if there is no existing one
with the same id and scope.
Now, once you have a bean,you can modify its properties via jsp:setProperty, or by using
a scriptlet and calling a method explicitly on the object with the variable
name specified earlier via the id attribute. You read existing properties in a JSP expression
or scriptlet by calling the appropriate getYYY method,
or more commonly, by using the jsp:getProperty
action.
Here is a very simple example that loads a bean and sets/gets a
simple String parameter.
test.jsp
<HTML>
<HEAD>
<TITLE> JavaBeans in JSP</TITLE>
</HEAD>
<BODY>
<jsp:useBean id="test" class="com.EmpBean" />
<jsp:setProperty name="test"
property="name"
value="Das" />
Name is :
<jsp:getProperty name="test" property="name" />
</BODY>
</HTML>
Output is :
Name is : Das
EmpBean.java
Here's the source code for the bean used in the test.jsp page.
package com;
public class EmpBean {
private String name = "";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
The below code
<jsp:useBean id="test" class="com.EmpBean" />
is equivalent to
com.EmpBean test = new com.EmpBean();
and
<jsp:setProperty name="test"
property="name"
value="Das" />
is equivalent to
test.setName("Das");
and
<jsp:getProperty name="test" property="name" />
is equivalent to
out.println(test.getName());
| Atribute
| Usage
|
id
| Gives a name to the variable that will reference the bean. A
previous bean object is used instead of instantiating a new one
if one can be found with the same id
and scope.
|
class
| Designates the full package name of the bean.
|
scope
| Indicates the context in which the bean should be made available.
There are four possible values: page,
request, session, and application.
The default, page, indicates that the bean is only available on the current
page (stored in the PageContext of the current page). A value of request
indicates that the bean is only available for the current client request
(stored in the ServletRequest object). A value of session indicates
that the object is available to all pages during the life of the current
HttpSession. Finally, a value of application indicates that it is
available to all pages that share the same ServletContext. The reason
that the scope matters is that a jsp:useBean entry will only result
in a new object being instantiated if there is no previous object
with the same id and scope. Otherwise the previously existing object
is used, and any jsp:setParameter elements or other entries between
the jsp:useBean start and end tags will be ignored.
|
type
| Specifies the type of the variable that will refer to the object.
This must match the classname or be a superclass or an interface that
the class implements.
Remember that the name of the variable is designated via the
id attribute.
|
beanName
| Gives the name of the bean, as you would supply it to the instantiate
method of Beans. It is permissible to supply a type and a
beanName, and omit the class attribute.
|
|
|