| Author |
Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I
|
Ray Smilgius
Ranch Hand
Joined: Jan 29, 2001
Posts: 120
|
|
I am confused, I am using an example with Tomcat4.0, See code snippets below: /////////////////////////////////////SErvlet 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("/foo.jsp").forward (req, res); } } //////////////////////////BEAN public class Foo { String s[]; public String[] getList() { return s; } public Foo(String s[]) { this.s = s; } } ///////////////////////////JSP Page <html> <usebean name=foo type=.Foo lifespan=page> </usebean> <ul> <loop property=foo:list propertyelement=x> <li> <display property=x> </loop> </ul> </html> ////////////////////////Question I know that my path is wrong in the getServletContext().getRequestDispatcher("/foo.jsp").forward (req, res); But I dont get an exception even if I try to catch it, I am using Tomcat 4.0 and Apache Question how can i get the correct path set to display this data source from bean to foo.jsp here is my path C:\jakarta-tomcat-4.0\webapps\InScopeFortKnox\IWA\foo.jsp my browser path http://rsmilgius:8080/InScopeFortKnox/IWA/login/foo.jsp this will show only a dot <UL> in the browser. please direct me to setting the the correct request getServletContext().getRequestDispatcher("/foo.jsp").//path to foo.jsp ??? Thanks in advance Ray ------------------ Sun Certified Java Programmer Sun Certified Java Developer I-Net Certified A+ Certified Network+ Certified MCP [This message has been edited by Ray Smilgius (edited November 15, 2001).]
|
SCJO, SCJD, SCWCD, I-Net+, A+, Network+, MCSD, MCDBA, MCP, MCT
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
With "/foo.jsp" you are addressing the page as if it is at the root directory of the server - but from the other URLs it looks like it lives at: /InScopeFortKnox/IWA/login/foo.jsp There is also a problem with this tag <usebean name=foo type=.Foo lifespan=page> </usebean> The attribute is not "lifespan" but "scope" and you need to have it set to "request" not "page" - also you should always put the tag attributes in quotes and you have to have the jsp namespace, so-- <jsp:usebean name="foo" type=".Foo" scope="request"> </jsp:usebean>
|
Java Resources at www.wbrogden.com
|
 |
Ray Smilgius
Ranch Hand
Joined: Jan 29, 2001
Posts: 120
|
|
Thanks Bill, This is an example, I found on the net. Thanks for the info. I will continue attempting this bean with your input. Thanks Ray Smilgius ------------------ Sun Certified Java Programmer Sun Certified Java Developer I-Net Certified A+ Certified Network+ Certified MCP
|
 |
 |
|
|
subject: Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I
|
|
|