Forums Register Login

Why is my RequestDispatcher null?

+Pie Number of slices to send: Send
WHy is that rd null? I printed if null then print something to the screen and sure enough it was null. Why?
public void service(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException

{
RequestDispatcher rd = getServletContext().getRequestDispatcher("mcserver_history.jsp");

HashMap hostnameMap = populateObject();
request.setAttribute("hostnameMap",hostnameMap);
rd.forward(request,response);
}
+Pie Number of slices to send: Send
It seems likely that that string creates an invalid URL as far as the servlet context is concerned.
Bill
+Pie Number of slices to send: Send
It is not the URL, that is the problem.
+Pie Number of slices to send: Send
Hi Anthony
The following is lifted from the API docs for ServletContext.getRequestDispatcher():


Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.
The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.


Your pathname does not begin with a "/" character - have you tried changing this?
[ October 24, 2003: Message edited by: Michael Fitzmaurice ]
[ October 24, 2003: Message edited by: Michael Fitzmaurice ]
+Pie Number of slices to send: Send
If you don't like that, you should try the

request.getRequestDispatcher() method, where the API indicates a more forgiving attitude:

The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root.
mooooooo ..... tiny ad ....
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 4078 times.
Similar Threads
Using RequestDispatcher Forward method giving NullPointer Exception
based on the output from the filter class, how do i mention which view page needs to be laoded
RequestDispatcher.include a jspx fragment from a filter
Servlet Response
passing parameter from jsp to servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 06:17:24.