Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed, in Servelet

 
Somnath Das
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i have a register page, when i fill in the zip code on my jsp page i pass this info to a servelet and after that process some thing from the database and i redirect the same page using
response.sendRedirect("register.jsp?cityname="+city_name+"&statename="+state_name);

but after this statement is executed i am facing the error as shown below(the entire stack trace i am giving for referance)

11:40:54,801 INFO [STDOUT] java.lang.IllegalStateException
11:40:54,801 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteResponseFacade.sendRedirect(CoyoteResponseFacade.java:352)
11:40:54,801 INFO [STDOUT] at ZipcodeGenerator.doPost(ZipcodeGenerator.java:163)
11:40:54,817 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
11:40:54,817 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
11:40:54,817 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
11:40:54,817 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
11:40:54,833 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:44)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
11:40:54,833 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:169)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
11:40:54,833 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
11:40:54,848 INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
11:40:54,848 INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
11:40:54,848 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
11:40:54,848 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
11:40:54,864 INFO [STDOUT] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
11:40:54,864 INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
11:40:54,864 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)



i would be really gratefull, if any one could solve this problem

Thank you,
Somnath Das.
 
Amit Ghai
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your ZipcodeGenerator servlet.
 
Somnath Das
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


ResultSet rs = null;
Statement stmt;
String sql;
DatabaseConnection db = new DatabaseConnection();


response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();








try
{

sql="select city_info.City, state_info.State_name from city_zip_area_code_master as city_info," +
"country_state_code_master as state_info where city_info.Zip='"+ value + "' "+
"and city_info.State_ID=state_info.State_ID";

Connection conn =db.getConnection();

stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
if(rs.next())
{

response.sendRedirect("register.jsp?cityname="+rs.getString("City")+"&statename="+rs.getString("State_name"));



}

}
catch(Exception ex)
{
ex.printStackTrace();
}


}



Thank you,
Somnath Das.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've already written, flushed and closed the output, so you can't redirect anymore.
Remove the following code (Or put it in a "else" statement.) and try again.



I recommend you to call "return;" after the sendRedirect to avoid further writing.
 
naidu gulla
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IllegalStateException is generated when we flush the response before doing a redirect
 
Somnath Das
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for our support..., I removed the flush .., but still facing the same problem

Any idea?

Thank you,
Somnath Das.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly. IllegalStateException is generated when we redirect after the response has been committed.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for our support..., I removed the flush .., but still facing the same problem


Really ? You removed everything except the db stuff and the redirect ?
Did you recompile ? (try to restart the server just in case)
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an entry in our Servlets FAQ that covers IllegalStateException and some of the most common causes.
You can see it here.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic