This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes Forwarding Servlet output to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Forwarding Servlet output to JSP" Watch "Forwarding Servlet output to JSP" New topic

Forwarding Servlet output to JSP

saahil sinha
Ranch Hand

Joined: Apr 07, 2003
Posts: 68
I would like ot know how i could redirect output of a servlet to a jsp page
I am using this piece of code for the servlet
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet

public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
RequestDispatcher rd;
rd=getServletContext().getRequestDispatcher("c:\\Program Files\\ApacheGroup\\Tomcat 4.1\\webapps\\ROOT\\display.jsp");
and for the jsp i am using this code:
<%String msg=(String)request.getAttribute("message");%>
but the ouput of the servlet is not being forwarded to jsp and neither is the jsp page opening wht have i missed out in this code.
Chris Smith
Ranch Hand

Joined: May 03, 2002
Posts: 42
You've forgotten that getRequestDispatcher requires a context-relative URI, not an absolute file name. Include the path starting with the context root, using a forward slash as a file separator according to the standard syntax for URIs.
I agree. Here's the link:
subject: Forwarding Servlet output to JSP
It's not a secret anymore!