I just (accidently) did this, and JRun generated bad Java code. (Granted,
it was a <loop> tag and not a simple <display> tag, so maybe there's some
difference between the two.)
But this could just be a design decision made by the makers of JRun -
maybe other JSP implementations will let you get away with it. (Just to be
picky, the spec does say "Any non-implicit Bean must first be declared this
way before it and its properties can be accessed later in the .jsp file."
And the data bean isn't a JSP implicit bean, so it would seem that the
<usebean> tag should be required.)
> -----Original Message-----
> From: A mailing list about Java Server Pages specification
> and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Hien Luu
> Sent: Tuesday, April 06, 1999 2:41 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Model 2. How to implement?
>
> I believe, the JSP page can grab the "MyDataBean" off the session
> object w/o using the <usebean>
>
> Hien
>
>
> -----Original Message-----
> From: Taggart Gorman [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, April 06, 1999 2:26 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Model 2. How to implement?
>
>
> JavaGuy writes:
>
> > I have a simple question:
> > How does one implement "Model 2" as described in the jsp specs?
> > I would like a servlet to get the replies from the user and
> > use JSP to display the results. There are no examples in the
> > documentation or the example code... How does the servlet call
> > the JSP page?
>
> The servlet doesn't "call" the JSP, it either redirects or
> forwards to it.
>
> One method would be to use
> HttpServletResponse.sendRedirect(String) from
> within the servlet to tell the client browser to go to the
> JSP. However,
> this causes an extra round trip from the client to the server.
> The preferred method (IMHO) in the 0.92 spec is to use
> RequestDispatcher.forward(String) to have the web server
> "automagically"
> forward input from a second URL within the same connection.
> You can get a
> RequestDispatcher by calling
> ServletContext.getRequestDispatcher(). Note
> that this is a new addition to the servlet spec (2.1 I
> think), and is not
> supported by all JSP implementations. I know for a fact that
> it is support
> in JRun 2.3. Check the JSP FAQ for more information on JSP
> implementations.
>
> And I'll jump the gun and tell you how to pass objects from
> a servlet to a
> JSP, just in case.
>
> In the servlet, create the object you want to access in the
> JSP. The
> object should be "JavaBean-like" and use get/set methods to
> access data.
> Then stuff the object into the current HttpSession, like so:
>
> MyDataBean bean = new MyDataBean ();
> HttpSession sess = req.getSession(true);
> sess.putValue("databean", MyDataBean );
>
> Then in the JSP you forward() to, use the following JSP
> tags to get the
> bean and access it:
>
> <usebean name=databean type=com.tradiant.MyDataBean>
> </usebean>
>
> <display property=databean:myData>
>
> And that's it. (Note that the name of the object you put
> into the session
> and the name in the <usebean> tag are the same - that's the
> trick to passing
> objects between servlets and JSPs.)
>
> Hope this helps.
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".