Marc Bordessoule wrote:
>
> Hi,
>
> I am trying to dynamically include a servlet in a jsp page but i receive
> a Internal Servlet Error:
>
> 1 - the page.jsp
> ...
> <jsp:request include="/servlet/myservlet" />
> ....
>
> 2 - the servlet :
>
> public class myservlet extends HttpServlet
> {
>    public void doGet(HttpServletRequest req, HttpServletResponse resp)
>                      throws ServletException, IOException
>    {
>  resp.setContentType("text/html");
>  PrintWriter out = new PrintWriter(resp.getOutputStream());
>  out.println("my informations");
>    }
> }
>
> 3 - and when i load the page.jsp for the first time (compilation) i
> receive the following message :
>
> Included servlet error: 500: Internal Servlet Error:
>
> java.lang.IllegalStateException: Writer is already being used for this
> request

As the exception message says, the "writer is already being used" ;-)

The JSP processor uses response.getWriter() to get a PrintWriter when it
receives the request. When you include the same response object is used
and when you have called getWriter you can not call getOutputStream on
the same response object. I'm not sure why you create your own PrintWriter
like you do in your servlet, but try

  PrintWriter out = resp.getWriter();

instead. That should solve the problem.

--
Hans Bergsten           [EMAIL PROTECTED]
Gefion Software         http://www.gefionsoftware.com

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to