Java.lang.IllegalStateException
Org.apache.catalina.connector.ResponseFacade.sendRedirect (responsefacade.java:423)
After analyzing and viewing the JDK document finally find a solution, add the return statement after the Response.sendredirect () method, as follows:
Response.sendredirect (login.jsp);
return null;
The reason: The Response.sendredirect () method was called two times in the program.
It is clear in the jdk5.0 documentation that there is a possibility of a IllegalStateException exception:
1) Call the Response.sendredirect () method again on the same page.
2) URL error submitted, which is not a valid URL.
PackageCom.servlet;ImportJava.io.*;ImportJava.sql.*;Importjavax.servlet.http.*;Importjavax.servlet.*;ImportJavax.swing.JOptionPane;ImportCom.bean.DataByPage;ImportCom.sun.rowset.CachedRowSetImpl; Public classHandlemodifyextendsHttpServlet {/** * */ Private Static Final LongSerialversionuid = 1L; @SuppressWarnings ("Restriction") Cachedrowsetimpl RowSet=NULL; @Override Public voidInit (servletconfig config)throwsservletexception {//TODO auto-generated Method Stub Super. init (config); Try{class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver"); } Catch(Exception e) {System.out.println ("Not loaded into the driver"); }} @Override Public voidDoPost (httpservletrequest req, HttpServletResponse resp)throwsservletexception, IOException {//TODO auto-generated Method Stubreq.setcharacterencoding ("GB2312"); HttpSession Session= Req.getsession (true); /** True: If the session is present, the session is returned, otherwise a new session is created, and false: * If the session exists, the session is returned, otherwise null is returned. */String Id= Req.getparameter ("Identity"); String Password= Req.getparameter ("Password"). Trim (); String Again_password= Req.getparameter ("Again_password"). Trim (); //Boolean B = password.length () > 0 && again_password.length () > 0;Connection con =NULL; String CDN= ""; Databypage Databean=NULL; Try{Databean= (databypage) session.getattribute ("Databean"); if(Databean = =NULL) {Databean=NewDatabypage ();//Creating ObjectsSession.setattribute ("Databean", Databean); } } Catch(Exception exp) {Databean=NewDatabypage ();//Creating ObjectsSession.setattribute ("Databean", Databean); } if(Password = =NULL) Password= ""; if(!password.equals (Again_password)) { //userbean.setbacknews ("Two times password is different, registration failed");Joptionpane.showmessagedialog (NULL, "you entered a different password, please re-enter", "Error", Joptionpane.error_message); Resp.sendredirect ("/demo9/student/modify.jsp"); return;//You have to add a return or you will report java.lang.IllegalStateException}Try{con=Drivermanager.getconnection ("Jdbc:sqlserver://127.0.0.1:1433;databasename=manage", "Wyc", "123456"); Statement SQL=con. createstatement (resultset.type_scroll_sensitive, Resultset.concur_ READ_ONLY);CDN = "Update users set password= '" + Password + "'" + "where idnumber= '" + Id + "'"; ResultSet RS=Sql.executequery (CDN); RowSet=NewCachedrowsetimpl (); Rowset.populate (RS);//reprint the RS record into the Cachedrowsetimpl object, then close the database connection and release the resourceDatabean.setrowset (RowSet); Con.close (); } Catch(SQLException ex) {System.out.println (ex); } resp.sendredirect ("/demo9/tiaozhuan.jsp"); }}
Java.lang.IllegalStateException