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>
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>