This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding Servlet output to JSP

 
saahil sinha
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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.*;
import java.io.*;
public class test extends HttpServlet
{

public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
req.setAttribute("message","hello");
RequestDispatcher rd;
rd=getServletContext().getRequestDispatcher("c:\\Program Files\\ApacheGroup\\Tomcat 4.1\\webapps\\ROOT\\display.jsp");
rd.forward(req,res);
}
}
and for the jsp i am using this code:
<html>
<body>
<%String msg=(String)request.getAttribute("message");%>
<%=msg%>
</body>
</html>
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic