This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Question getServletContext().getRequestDispatcher( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I" Watch "Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I" New topic

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:
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);
(req, res);
public class Foo {
String s[];
public String[] getList() { return s; }
public Foo(String s[]) { this.s = s; }
///////////////////////////JSP Page
<usebean name=foo type=.Foo lifespan=page>
<loop property=foo:list propertyelement=x>
<li> <display property=x>
////////////////////////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
my browser path
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
[This message has been edited by Ray Smilgius (edited November 15, 2001).]

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12758
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:
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>
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.
Ray Smilgius
Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I
Similar Threads
i can't understand this sentence ~~please help me,thanks
Urgent : Servlet to Servlet(in another server)
fowarded from servlet to jsp but in the browser it shows the servlet name???
trouble passing info from servlet to jsp
Error using forward method