tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steve Haines <>
Subject RE: Can i use <jsp:useBean .. tag with Model 2 Architecture ? ?
Date Thu, 15 Jun 2000 15:09:22 GMT
> I try to avoid scriptlets -- except when
> I have to iterate through a ResultSet.

Take a look at Web Development with JavaServer Pages by Manning Publishing,
they give an example of a custom taglib to replicate both an "if" statement
as well as a "for" loop so that your JSP pages can be even more simple..
Here is an example of looping through all of your employees:

Two beans:

EmployeeList has 3 methods:
public Employee getEmployee( int index );
public void setEmployee( int index, Employee employee );
public int getEmployeeSize();

JSP File:

<jsp:useBean id="employeeList" class="mypackage.EmployeeList"


<mytaglib:forProperty name="employeeList" property="employee" id="employee"

	Employee name: <jsp:getProperty name="employee" property="name"/>


Pretty clean, huh?  Like I said, take a look at Web Development with
JavaServer Pages ( or search for more information on custom
taglibs (as a matter of fact there	is a Jakarta project on custom tag
libs) if you are interested.. It will make your web designers using
Dreamweaver to generate JSP pages lifes' much easier!


-----Original Message-----
From: Ken Kress []
Sent: Thursday, June 15, 2000 5:55 AM
Subject: Re: Can i use <jsp:useBean .. tag with Model 2 Architecture ? ?


I'm still learning, but I started off with useBean and really like
it. It seems very clean. I try to avoid scriptlets -- except when
I have to iterate through a ResultSet.

What I do is set up a bean to hold information from the query. I've
seen people put the query glue into a servlet, but I've made the
bean more active. It knows to establish the db connection, do
the query and fill in the instance variables.  In my JSP, I just
getProperties. It's sweet.

I'm using model 2, also. I like to think of the beans as state
machines. The controller servlet can check the state and take
appropriate action. I'm using a hashMap for the dispatching, but
will be moving it into a db table before I go live. It should let
me re-use my beans and JSPs on other projects.


Ken Kress                     
Osprey Partners LLC                                  610.240.7289

----- Original Message -----
To: <>
Sent: Wednesday, June 14, 2000 10:49 PM
Subject: Can i use <jsp:useBean .. tag with Model 2 Architecture ? ?

I am developing a project with servlets,JSP and jDBC and i am almost
exclusively using Model 2 architecture.
But i never use <jsp:useBean tag in my JSP files.
Is there a way to use that tag and also <jsp:getProperty ... with Model 2 ?
My approach is the following :
All the requests from the JSP files go to a Controller servlet.
In  this servlet then i instantiate the Database bean as  :

EmployeeBean employee  = new EmployeeBean(request, response);
    // now the EmployeeBean holds all the values from the database
request.setAttribute("emplyeeBean" , employee);
t, response);

In the employee.jsp file i do :

    EmplyeeBean employee = (EmployeeBean)
<TR><TD><%= employee.getLastName() %></TD></TR>

The above is the case when i want to display ONE record.
When i want to display many records from a search i usually create the
Resultset object from my bean
and in the servlet i  put the Resultset object in the Request , and then I
retrieve the ResultSet in my JSP as :
    ResultSet rs = (ResultSet) request.getAttribute("myresultSet")

<TR><TD><%= rs.getString(1) %></TD></TR>  ...etc ...

So where is the use of <jsp:useBean tag with Model 2 ?
I never need to instantiate a bean directly from any JSP file. All the beans
are instantiated within the Servlet Controller.
Also the above approach keeps pretty clean the JSP files from JAVA code.

Am i missing something ? ?

To unsubscribe, email:
For additional commmands, email:

View raw message