日期:2014-05-20  浏览次数:20857 次

有异常 找不到
package com.test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

public class testServlet extends HttpServlet {

/**
* Constructor of the object.
*/
 

public testServlet() {
super();


}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>

* This method is called when a form has its tag value method equals to get.

* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
// String s1=request.getParameter("Submit");
// if(s1!=null &&s1.equals("登录")){
// String zhanghao=request.getParameter("textfield");
// String mima=request.getParameter("textfield2");
// if(zhanghao.equals("abc")&&mima.equals("123")){
// response.setContentType("text/html; charset=gbk");

// response.sendRedirect("/Login.jsp");
// }
//

// }
}

/**
* The doPost method of the servlet. <br>

* This method is called when a form has its tag value method equals to
* post.

* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String t1 = request.getParameter("textfield");
String t2 = request.getParameter("textfield2");
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");

conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/user?user=root&password=root");
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from user_info");

while (rs.next()) {

  if(t1.equals(rs.getString("username"))&& t2.equals(rs.getString("pwd"))){
   
  response.sendRedirect("./Login.jsp");
  }
  else{
  System.out.print("111112222222222222222");
  }

}

}
catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException ex) {
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
} finally {
try {
if (rs != null) {
rs.close();
rs = null;
}
if (stmt != null) {
stmt.close();
stmt = null;
}
if (conn != null) {
conn.close();
conn = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}

}

/**
* Initialization of the servlet. <br>

* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}

}




报的错误
2011-11-16 14:54:04 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2011-11-16 14:54:04 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/31 config=null
2011-11-16 14:54:04 org.apache.catalina.startup.Catalina start
信息: Server startup in 1324 ms
SQLException: Operation not allowed after ResultSet closed
SQLState: S1000
VendorError: 0

------解决方案--------------------
貌似是finally那段的错,把那些注释掉试下。