Hello Everybody, Can anybody give me a code for the following purpose: I want to forward a request from Servlet to JSP using RequestDispatcher interface's forward method.problem i am facing is how to give a url(either absolute or relative for JSP).
Extra Info: I am using Weblogic 6.1 where i have copied Servlet .class files in classes folder, whereas JSP is located in DefaultWebApp.
It depends on the servlet url path defined in web.xml. Say, your servlet is called by http://server.com/MyApp/MyServlet. Then from the servlet you can forward to a JSP like:
// Use the relative path from the servlet. RequestDispatcher rd = request.getRequestDispatcher("Result.jsp"); rd.forward(request, response);
// If servlet uri is http://server.com/MyApp/someDir/MyServlet and jsp is right under web root directory, // by using relative path from servlet RequestDispatcher rd = request.getRequestDispatcher("../Result.jsp"); // by using relative path from host server RequestDispatcher rd = request.getRequestDispatcher("/MyApp/Result.jsp"); rd.forward(request, response);
Hope this helps. [ April 03, 2005: Message edited by: Heonkoo Lee ]