Thanks Joe. Both your responses are very helpful to me. If I store my
resultset in an Employee[] (or Vector), to avoid having to keep my
connection open, you're saying I can store it in a session attribute.
I presume I would have to declare the Employee[] using a declaration
(<%!...%> before accessing it in the jsp using
<%Employee[] e=(Employee[])session.getAtrribute("allemployees");%>

When would I use a bean to store this data, either record-by-record
(public String getFirstName(), public void setFirstName(String first))

or as a collection
public Employee[] getRecords(), public void setRecords(Employee[])?

The second is less straightforward, but may be a possibility to store
the collection for later retrieval. I only today learned that beans
are classes with getters and setters; I didn't know I had been using
them for months. Anyway, the tag syntax of a bean seems to be another
way to get the data, if the bean can be "set" in a servlet and
retrieved in a jsp. Is there a clearer way to think about beans in
the context of passing info from a servlet to a jsp?

John



------------------ Reply Separator --------------------
Originally From: Joe Cheng <[EMAIL PROTECTED]>
Subject:  Re: newbie wanting to pass data from servlet to jsp
Date: 12/10/2001 03:47pm


You can store the objects you want to pass in the request scope.

public void request.setAttribute(String attrname, Object value)
public Object request.getAttribute(String attrname)

Your servlet code would look like:

 request.setAttribute("myData", rs);
 request.getRequestDispatcher("path_to_jsp").forward(request,
response);

Your JSP code would look like this:

 ResultSet rs = (ResultSet)request.getAttribute("myData");

If you want to store the object for a larger scope than just the
current
request, you can store it in the session (same syntax).

"<%@ page import=" is like import statements in your Java classes.
For
example, if your servlet has this:

import java.util.*;
import java.sql.ResultSet;

Your JSP equivalent would be this:

<%@ page import="java.util.*,java.sql.ResultSet" %>

-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

Reply via email to