tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Can i use <jsp:useBean .. tag with Model 2 Architecture ? ?
Date Thu, 15 Jun 2000 02:49:16 GMT
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);
getServletContext().getRequestDispatcher("/jsp/employee.jsp").forward(request, response);

In the employee.jsp file i do : 

    EmplyeeBean employee = (EmployeeBean) request.getAttribute("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")
    while( { 
<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 ? ?

View raw message