这两天我试图找出问题所在。我在这里读到我应该在代码中添加一个返回,我做到了,我仍然得到
java.lang.IllegalStateException: Cannot call sendRedirect()
after the response has been committed, Error.
我怎么解决这个问题?
每次我连接到数据库时都会发生这种情况。这是连接方法:
<%!
public void connect()
{
try {
Class.forName("com.mysql.jdbc.Driver");
String dbURL = "jdbc:mysql://localhost:3306/moti";
String user = "root";
String password = "j3o4h5n6y7";
con = DriverManager.getConnection(dbURL, user, password);
statement = con.createStatement();
}
catch(Exception ex) {
throw new Error(ex);
}
}
%>
就像在这个代码块中:
String post = request.getParameter("send");
if(post != null )
{
connect();
statement.execute(add);
con.close();
response.sendRedirect("fourm.jsp");
return;
}
但在这段代码中完美地阻止了它的工作:
String back = request.getParameter("retrun");
if(back != null)
{
response.sendRedirect("fourm.jsp");
return;
}