servlet已经取出了数据,显示在html上
servlet:
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Connection conn = DBConnectUtils.getConnection();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
String sql = "select id,username from User";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (rs != null) {
while (rs.next()) {
req.setAttribute("id", rs.getInt("id"));
req.setAttribute("username", rs.getString("username"));
req.getRequestDispatcher("showUser.html").forward(req,
resp);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
DBCloseUtils.closeCSR(conn, pstmt, rs);
}
}
ajax应该怎么写