File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes RequestDispathcher Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispathcher" Watch "RequestDispathcher" New topic
Author

RequestDispathcher

vinay bedidha
Greenhorn

Joined: Oct 04, 2001
Posts: 9
i want to transfer control from a servlet to JspPage("Home.jsp")
iam getting a problem when using
RequestDispatcher rd=getServletContext().getRequestDispathcher("/Home.jsp");
iam getting NullPointerException problem.if i use response.sendRedirect("/Home.jsp"); it's working fine.
what's the problem with RequestDispatcher?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

(This appears to be a continuation of the thread here)
What configuration are you using, is there a web server in front? sendRedirect() forces the browser to make a re-request for the specified page and hence comes from "the outside world". getRequestDispatcher().XXX() loads and returns the respource from the server within the application context.
Dave.
vinay bedidha
Greenhorn

Joined: Oct 04, 2001
Posts: 9
hi David,
Thanks for your answer.
iam using Borland Application server and jsdk2.0.when iam using RequestDispatcher, during compilation time it's giving error message as follows..
unable to Resolve symbol RequestDispathcher rd=getServletContext().getRequestDispatcher("/Home.jsp");
plz help me..
thanks
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
Where is "Home.jsp" located with respect to the root of your war file? That might make a difference.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

There might be a clue in the API

The original problem was that getRequestDispatcher() and request.getRequestDispatcher() seemed to offer different behaviour.

From the API: The difference between this method
[ ie: HttpRequest.getRequestDispatcher(java.lang.String) ]
and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.
Mouse Slider
Greenhorn

Joined: Nov 02, 2001
Posts: 4
getServletContext().getRequestDispatcher("Home.jsp").include(request, response);
getServletContext().getRequestDispatcher("Home.jsp").forward(request, response);
cheers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RequestDispathcher
 
Similar Threads
Cannot access servlet after deploying website on cpanel
RequestDispathcher
Problem with cvs
java 1.5 ( generics and autoboxing) not working in Tomcat 5.5.9.
installing plugin for netscape and mozilla