Hi,
At this moment I am a little confused about the technique of useBean in JSP
if collections are passed.
It would be probably a typical situation when the controller/action servlets
pass back to JSP some collection, for instance a Vector or ArrayList
containing generated beans.
If you use a session for servlet-JSp communication, your code might look
something along these lines:
// Action implementation class code
HttpSession session = req.getSession (false);
if (session == null) {
res.sendRedirect("http://localhost:8080/error.html");
}
String myAttribute = (String)session.getAttribute("myAttrname");
// do some calculations
ArrayList myResponce = ...
session.setAttribute ("myResponseName", myResponce );
// pass execution and bean to display JSP
String url="/jsp/myJsp.jsp";
ServletContext sc = servlet.getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher (url);
rd.forward (req, res);
// JSP code
ArrayList responseAttr = (ArrayList)
session.getAttribute("myResponseName");
if (responseAttr != null && (responseAttr .size() >0)) {
// work with the bean here, draw HTML table containing returned data
or whatever
}
While I understand the benefits of using request instead of session, I
cannot figure out the syntax on JSP to get the request, i.e. if Action class
stores response class in request and not in session. Is it just the same as
for session, i.e. instead of calling session.getAttribute we retrieve a
collection from request.getAttribute, and then iterate through the
collection collecting bean properties?
BTW, what Craig names Action interface appears to me to resemble pretty
close a Command pattern fro GoF book. Yes, and it has a method Execute.
Vadim.
-----Original Message-----
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Saturday, March 25, 2000 10:03 PM
Subject: Re: Model 2 questions
...
Yes, the <jsp:useBean> in the JSP page grabs it back out. You have to match
on
the scope where your servlet placed the bean, as well as the name you stored
it
under. In the case above, it would be something like:
<jsp:useBean id="MyBeanName" scope="request" class="....."/>
or
<jsp:useBean id="MyBeanName" scope="request" type="....."/>
(The latter is nice because you can use an interface if you've got
polymorphic
beans -- for the usual case I just use class= instead.)
...
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets