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:
...
jsp="main.jsp";
RequestDispatcher dispatcher;
dispatcher= context.getRequestDispatcher(jsp);
dispatcher.forward(req,res);
}
}
And here is my main.jsp
------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">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<LINK rel="stylesheet" type="text/css" href="css/webiz.css">
<TITLE>
WeBiz
</TITLE>
</HEAD>
<BODY topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">
...
<jsp:include page="/busca_cliente" flush="true"></jsp:include>
</TD>
</TR>
<TR>
<TD height="5%" valign="TOP" class="tabela_header">
</TD>
</TR>
</TABLE>
</BODY>
</HTML>
-
<jsp:include problem> (3 messages)
- Posted by: Jeff Almeida
- Posted on: December 30 2001 10:13 EST
Threaded Messages (3)
- <jsp:include problem> by Usha Iengar on December 31 2001 11:38 EST
- <jsp:include problem> by Jeff Almeida on January 02 2002 14:23 EST
- <jsp:include problem> by joseph yi on January 07 2002 20:35 EST
-
<jsp:include problem>[ Go to top ]
- Posted by: Usha Iengar
- Posted on: December 31 2001 11:38 EST
- in response to Jeff Almeida
try
dispatcher.include(req,res);
instead
Usha -
<jsp:include problem>[ Go to top ]
- Posted by: Jeff Almeida
- Posted on: January 02 2002 14:23 EST
- in response to Usha Iengar
I already change the code but I had the same problem.
-
<jsp:include problem>[ Go to top ]
- Posted by: joseph yi
- Posted on: January 07 2002 20:35 EST
- in response to Jeff Almeida
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!
or
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");
or
// if a parameter was passed through the servlet
request.getParameter("fromServlet");