This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
Hi Dileep, If you see the Servlet API for the method getRequestDispatcher, it goes as follows ---------------------------------------------------------- getRequestDispatcher public RequestDispatcher getRequestDispatcher(java.lang.String path) 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. Parameters: path - a String specifying the pathname to the resource Returns: a RequestDispatcher object that acts as a wrapper for the resource at the specified path See Also: RequestDispatcher, getContext(java.lang.String) ------------------------------------------------------------- Found the problem in your code? It should be relative path, not absolute path according to specification. Use it like this RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/examples/JSP/Menu.jsp");
------------------ Prasad
<B>Prasad</B>
Dilip kumar
Ranch Hand
Joined: Oct 16, 2000
Posts: 360
posted
0
Prasad, Thank you for explaination. I changed the code to RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/examples/jsp/Menu.jsp"); dispatcher.forward(request,response); But problem is not yest solved. For some reason it's not loading Menu.jsp though I have this file in C:\jakarta-tomcat\webapps\examples\jsp
Hi Dilip, Since you are already adding some content to your response object, try using dispatcher.include(request,response); This will append the content of jsp file to your existing response.
I'm not sure why you're using the requestDispatcher in the first place. You should only really use it if you want to pass the original request and response objects. I realise that you're setting the "NoCache" pragma, but that would only be neccessary if you actually delivered content from this Servlet. Correct me if I'm wrong, but this situation looks to be a simple redirect(especially since you are redirecting to a jsp page, not a servlet). Why not use response.sendRedirect("someurl.com"); Hope this helps. Sean
Dilip kumar
Ranch Hand
Joined: Oct 16, 2000
Posts: 360
posted
0
Hi, As Sean mentioned I need simple redirect ( like reponse.redirect in ASP ). I changed the code to if (userid.length() > 0) { out.println("forwarding...."); response.sendRedirect("http://localhost:8080/examples/JSP/Menu.jsp"); } Address field in IE is changing to http://localhost:8080/examples/JSP/Menu.jsp But the application is crashing immediately. jasper.log ------------ Scratch dir for the JSP engine is: C:\jakarta-tomcat\work\localhost_8080%2Fadmin</JASPER_LOG> IMPORTANT: Do not modify the generated servlets</JASPER_LOG> JspEngine --> /jsp/logon.jsp</JASPER_LOG> ServletPath: /jsp/logon.jsp</JASPER_LOG> PathInfo: null</JASPER_LOG> RealPath: C:\jakarta-tomcat\webapps\examples\jsp\logon.jsp</JASPER_LOG> RequestURI: /examples/jsp/logon.jsp</JASPER_LOG> QueryString: null</JASPER_LOG> Request Params: </JASPER_LOG> Classpath according to the Servlet Engine is: C:\jakarta-tomcat\webapps\examples\WEB-INF\classes</JASPER_LOG> JspEngine --> /JSP/Menu.jsp</JASPER_LOG> ServletPath: /JSP/Menu.jsp</JASPER_LOG> PathInfo: null</JASPER_LOG> RealPath: C:\jakarta-tomcat\webapps\examples\JSP\Menu.jsp</JASPER_LOG> RequestURI: /examples/JSP/Menu.jsp</JASPER_LOG> QueryString: null</JASPER_LOG> Request Params: </JASPER_LOG> Classpath according to the Servlet Engine is: C:\jakarta-tomcat\webapps\examples\WEB-INF\classes</JASPER_LOG> servlet.log ----------- Context log path="/admin" :tomcat.errorPage: init Context log path="/admin" :jsp: init Context log path="/admin" :default: init Context log path="/examples" :tomcat.errorPage: init Context log path="/examples" :jsp: init Context log path="/examples" :default: init Context log path="/test" :tomcat.errorPage: init Context log path="/test" :jsp: init Context log path="/test" :default: init Context log path="" :tomcat.errorPage: init Context log path="" :jsp: init Context log path="" :default: init Context log path="/examples" :invoker: init Context log path="/examples" :VerifyUser: init tomcat.log ------------- Context log: path="" File not found C:\jakarta-tomcat\webapps\ROOT\WEB-INF\web.xml, using only defaults Starting endpoint port="8080" handler="org.apache.tomcat.service.http.HttpConnectionHandler" Starting endpoint port="8007" handler="org.apache.tomcat.service.connector.Ajp12ConnectionHandler"
Sean MacLean
author
Ranch Hand
Joined: Nov 07, 2000
Posts: 621
posted
0
Hmmmn. Looks like the problem is on the server/jsp side of things, not the servlet doing the redirect. I assume the Menu.jsp works fine when you access it normally. And if so, what url do you use to hit the Menu page? Sean