package servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import bean.Address;
import bean.DbConnect;
/**
-
Servlet implementation class loginServer
*/
@WebServlet("/loginServer")
public class loginServer extends HttpServlet {
private static final long serialVersionUID = 1L;/**
- @see HttpServlet#HttpServlet()
*/
public loginServer() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(“text/html”);
request.setCharacterEncoding(“utf-8”);
response.setCharacterEncoding(“utf-8”);
String user = request.getParameter(“user”);
String pwd = request.getParameter(“pwd”);
if (user.equals(“a”) && pwd.equals(“1”)) {
Connection connection = DbConnect.getConnection();
String sql = “select * from addressbook”;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List addressbook = null;
try {
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();
if (resultSet!=null) {
addressbook = new ArrayList();
try {
while (resultSet.next()) {
Address address = new Address();
address.setId(resultSet.getInt(1));
address.setName(resultSet.getString(2));
address.setPhone1(resultSet.getString(3));
address.setPhone2(resultSet.getString(4));
addressbook.add(address);
}
} catch (Exception e) {
System.out.println(“封装数据集失败”);
e.printStackTrace();
}
}
HttpSession httpSession = request.getSession();
httpSession.setMaxInactiveInterval(7200);
httpSession.setAttribute(“addressbook”, addressbook);
response.sendRedirect(“addresslist.jsp”);
}catch (SQLException e) {
System.out.println(“1”);
e.printStackTrace();
}catch (Exception e) {
// TODO: handle exception
System.out.println(“2”);
e.printStackTrace();
}}else { response.sendRedirect("login.jsp"); }
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
} - @see HttpServlet#HttpServlet()
}
有什么错误啊