The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Servlet JSP Communication

Posted by Ashok on December 06, 2000 at 4:11 AM

Hi all,

I would really appreciate if anybody can help me out on this one.
I am using the following Servlet Code and a JSP file. The Servlet uses the RequestDispatcher.forward method to send a value to the JSP.

I get the following error:
The servlet named UpdateJSPTest at the requested URL

reported this exception: Can not forward to servlet file : OutputStream or writer has been obtained. Please report this to the administrator of the web server.
It also reports an IllegalStateException and points to the line in the Servlet code which is: rd.forward(req, res);

The JSP file runs perfectly OK when I call it from the location bar on the browser(except that null is returned). I am using JavaWebServer2.0.

I fiddled around with java.policy and a few other things. Nothing seems to work. I think it is a very trivial problem which i am not able to figure out.


Servet Code:
public class UpdateJSPTest extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
String message = "This is a test";
req.setAttribute("message", message);
PrintWriter out = res.getWriter();
RequestDispatcher rd = getServletContext().getRequestDispatcher("");

JSP CODE:(note that < and > replaced with *)

*servlet code=UpdateJSPTest**/servlet*
String message = (String) request.getAttribute("message");
out.print("message: *b*" + message + "*/b*");
for (int i = 0; i * 5; i++)
out.println ("*li*" + i);



Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us