To me, the main advantage (or difference) to use a jsp bean (<jsp:usebean ...> over a class bean, i.e. a normal java class, is that you can clearly specify the life cycle of your bean objects using the "scope" attribute.
For example, if you use <jsp:usebean .... scope=session/> after the user exit (or when his session expired... I guess so, but am not very sure about this, you have to check the spec or "The JSP book" again ;-), all resources associated with his session are theoretically ready for garbage collection (unless you have circular reference among your objects). david -----Original Message----- From: A mailing list about Java Server Pages specification and reference [mailto:[EMAIL PROTECTED]]On Behalf Of Joe Cheng Sent: Monday, December 10, 2001 3:03 PM To: [EMAIL PROTECTED] Subject: Re: newbie wanting to pass data from servlet to jsp You do not have to do any declarations (of the <%! %> type) to do what you want to do. You would probably have to import the Employee class, is all. If Employee lived in a package com.mycom, just do <%@ page import="com.mycom.Employee" %> I personally never use the JavaBean framework, e.g. jsp:useBean, jsp:whatever. I just use scriptlets. My Employee class's interface would probably look something like this: public class Employee { public static Employee[] getAllEmployees() { ... } public static Employee getEmployee(int id) { ... } public static Employee createEmployee(String firstname, ...) { ... } private Employee(int id, String firstName, ...) { ... } public int getId() { ... } public void setFirstName(String firstName) { ... } public String getFirstName() { ... } ... } Note that this is not a JavaBean, and you probably wouldn't write the class this way if you intended to turn it into a JavaBean. (Hopefully someone else can point out the differences.) Anyway, your servlet: request.setAttribute("employees", com.mycom.Employee.getAllEmployees()); request.getRequestDispatcher("path_to_jsp").forward(request, response); your JSP: <%@ page import="com.mycom.Employee" %> Employee[] employees = (Employee[])request.getAttribute("employees"); -jmc =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com
