Found this at webdevelopersjournal.com

Might help you.....

(Contributed by: [EMAIL PROTECTED])
After scanning through archives of the JSP mailing list to no effect I
finally remembered that I'd pasted this example into a document I wrote. It
was originally sent by Satish Dharmaraj of Sun to show the model 2 approach
(as described in the 0.92 specification): how to pass data from a servlet
to a JSP.
Create a directory called model1/ under the samples/ directory. Place
foo.jsp and Foo.java inside this directory.
Compile FooServlet.java and place FooServlet.class in
TOP/servlets/directory.
Then invoke using http://host:8080/servlet/FooServlet
In this example, FooServlet creates a list and then stores the result in
Foo.class. Foo.Class is then passed as a datasource to foo.jsp.
The sources are:
1) FooServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import model1.Foo;

public class FooServlet extends HttpServlet
{
        public void service(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
        {
         String s[] = new String[] {"blue", "green", "red"};
         Foo f = new Foo(s);
         req.setAttribute("foo", f);


getServletContext().getRequestDispatcher("/samples/model1/foo.jsp").forward
         (req, res);
        }
}
2) foo.jsp
<html>
<usebean name=foo type=model1.Foo lifespan=page>
</usebean>
<ul>
<loop property=foo:list propertyelement=x>
<li> <display property=x>
</loop>
</ul>
</html>
3) Foo.java
package model1;

public class Foo {
        String s[];
        public String[] getList() { return s; }
        public Foo(String s[]) { this.s = s; }
        }
(from "O´Hare, Thomas Bernhard" <[EMAIL PROTECTED]>)




- V.M.

If it is to be, it is upto me.



> -----Original Message-----
> From: Farooq Hameed [SMTP:[EMAIL PROTECTED]]
> Sent: Thursday, May 04, 2000 2:27 PM
> To:   [EMAIL PROTECTED]
> Subject:      Re: How to call JSP from servlets.
>
> May be you can use this:-
>
>
> getServletContext().getRequestDispatcher("/hellow.jsp").forward(req,res);
>
> Regards
> Farooq Hameed
>
> ==========================================================================
> =
> 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

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