文档介绍:×÷Õߣºjspfuns
ÈÕÆÚ£º2000-8-10 17:49:53
10) How do you invoke a JSP page from a servlet? TOC
(Contributed by: Thomas--******@Dresdner-)
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 specification): how to pass data from a servlet
to a JSP.
Create a directory called model1/ under the samples/ directory. Place and inside this directory.
Compile and place 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 . is then passed as a datasource to .
The sources are:
import .*;
import .*;
import .*;
import ;
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);
("foo", f);
getServletContext().getRequestDispatcher("/samples/model1/").forward
(req, res);
}
}
<html>
<usebean name=foo type= lifespan=page>
</u