package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import att.Att;
public class Select_t extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a","root","0519");
String chack_sql = "select * from t_user";
ps = con.prepareStatement(chack_sql);
rs = ps.executeQuery();
List<Att> list = new ArrayList();
while(rs.next())
{
int id = rs.getInt("id");
String username = rs.getString("username");
String password = rs.getString("password");
Att a = new Att(id,username,password);
list.add(a);
}
request.setAttribute("list", list);
request.getRequestDispatcher("Show_t.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import att.Att;
public class Select_t extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
request.setCharacterEncoding("utf-8");
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/a","root","0519");
String chack_sql = "select * from t_user";
ps = con.prepareStatement(chack_sql);
rs = ps.executeQuery();
List<Att> list = new ArrayList();
while(rs.next())
{
int id = rs.getInt("id");
String username = rs.getString("username");
String password = rs.getString("password");
Att a = new Att(id,username,password);
list.add(a);
}
request.setAttribute("list", list);
request.getRequestDispatcher("Show_t.jsp").forward(request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}