why dont I get exception here(servlets)

M

Madhur Ahuja

According to javadocs in HttpServletReponse:

sendRedirect
If the response has already been committed,

this method throws an IllegalStateException.

After using this method, the response should be considered

to be committed and should not be written to.

I want to know, how can I commit the reponse. I tried
flushing the buffer, but still I didnt get IllegalStateException.

Running Tomcat 4.

Here is the code:

<html>
<head>
<title>servlet</title>
</head>

<body>
<%

if (request.getParameter("name")==null)
{
out.println("<h1>hello world</h1>");

out.flush();

response.setHeader("madhur","ahuja");
response.flushBuffer();

response.sendRedirect("/login.jsp");

}
else
{%>
<h1>hello <%=request.getParameter("name") %> </h1>
<%
}
%>


</body>
</html>
 
S

shakahshakah

If you just want to generate an IllegalStateException, you could
probably either set a small buffer size with a page directive or write
out more that the current buffer size (4 or 8kb) before using the
response.sendRedirect(). There's probably a page directive to disable
page buffering that would "help", too.
The directive is something like:
<%@ page buffer=8kb %>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top