<jsp:include problem>


Web tier: servlets, JSP, Web frameworks: <jsp:include problem>

  1. <jsp:include problem> (3 messages)

    Hi people.

    I had a problem with a <jsp:include> in my jsp.

    I wrote a servlet to control the process in my application. My servlet throws to a page called main.jsp. In this page, a put a <jsp:include> directive. If the contents of the directive is a static page, i.e. "index.html" , the program runs successfully, but, if I put a call to another servlet (i.e. which generate a news to the client) , I receive this exception message:

    java.lang.IllegalStateException: Response has already been committed

    If I call the page main.jsp direct into my browser, the include directive works fine and call my servlet.

    Here is a piece of my control servlet:

          RequestDispatcher dispatcher;
          dispatcher= context.getRequestDispatcher(jsp);
    And here is my main.jsp

    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="com.nexion.voyager.components.usuarioBean" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
      <LINK rel="stylesheet" type="text/css" href="css/webiz.css">
      <BODY topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
      <jsp:include page="/busca_cliente" flush="true"></jsp:include>


            <TD height="5%" valign="TOP" class="tabela_header">

    Threaded Messages (3)

  2. <jsp:include problem>[ Go to top ]

  3. <jsp:include problem>[ Go to top ]

    I already change the code but I had the same problem.
  4. <jsp:include problem>[ Go to top ]

    one common cause of IllegalStateException in the response is when you recursively include or forward.

    your control servlet forwards/includes the request to main.jsp

    however, in main.jsp you are including the response of the control servlet.

    so if someone accesses main.jsp, and no exception was caught, then you'd see the response of:

    main.jsp including servlet forwarding to main.jsp including servlet forwarding main.jsp etc. BAD!


    main.jsp inluding servlet including main.jsp including servlet including main.jsp etc. BAD!

    If you would like to access the request object in a JSP from a forwarded page, you simple use the implicit HttpServletRequest object.

    So in the JSP you can say:

    // if in servlet before forward:
    // request.setAttribute("msg", "something stored in HttpServletRequest");
    String s = (String)request.getAttribute("msg");


    // if a parameter was passed through the servlet