ajax如何获取servlet的数据

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应该怎么写
查看全部
kristenlee1218
kristenlee1218
2017/03/24 02:23
  • 数据
  • servlet
  • ajax
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

4个回复