• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question getServletContext().getRequestDispatcher("/foo.jsp").forward(req, res); I

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
 
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic