"Shun, Vadim" wrote:
>
> Hi,
>
> what is the alternative of passing classes through HttpSession from servlet
> classes to JSP?
> I've been using session in conjunction with:
>     ServletContext sc = servlet.getServletContext();
>     RequestDispatcher rd = sc.getRequestDispatcher (url);
>     rd.forward (req, res);
>
> and would like to change "session approach" to request/response pair when
> possible.
> While JSP-ToServlet change was easy (use request.getParameter on the server
> of JSP value placed in a form), I am shortsighted as to how to pass the data
> the other way without resorting to session.

If you only need the data to continue processing of the same request in a
JSP, you can use request attributes:

      ServletContext sc = servlet.getServletContext();
      RequestDispatcher rd = sc.getRequestDispatcher (url);
      req.setAttribute("foo", myBean);
      rd.forward (req, res);

The JSP page can then access the object from the request scope, e.g.

  <jsp:useBean id="foo" class="myPackage.MyBean" />

Note that the id attribute value must match the name you give the
attribute in the servlet.

Hans
--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
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

Reply via email to