如何在JSP页面中实现检索数据的分页显?
如何在JSP页面中实现检索数据的分页显示
下面将通过一些例程来说明实现JSP页面翻页技术的实现。首先,在JSP中,通过JAVA servlet 来检索数据,而用JSP来调用结果来显示。 因而,此技术可分为两个部分(依赖关系): 1。 在服务器端的servlet 中的实现 要点: 1)将查询条件保存到session中,取session中的查询条件 2)设置Statement对象的MaxRows(确定一页显示多少行数据) 3)顺序地通过执行SQL语句查询数据,按maxRows 来检索一个maxRows的数据, 下一页再检索下一maxRows的数据,以此类推。
2。 在JSP中的显示实现 要点: 1)显示maxRows条数据 2)通过“下一页”按钮或超链再次调用刚才的servlet查询下一maxRows的数据 流程如图所示: 下面通过一个例程来说明(一个servlet程序和一个JSP程序): l querymedicine。
java (Medicine。 querymedicine) package Medicine; import javax。servlet。*; import javax。servlet。http。*; import java。io。*; import java。
util。*; import java。sql。*; import Medicine。medicinelist; import Medicine。searchData; //////////////////////////////////////////////////// // 接---mutiquery。
jsp页面,并从request中得到5条查询条件 /// // 按条件查询药品,并将结果存进session的“medicinelist”中。 /// //////////////////////////////////////////////////// public class querymedicine extends HttpServlet { private DBConnectionManager connMgr; //Initialize global variables public void init(ServletConfig config) throws ServletException { super。
init(config); connMgr = DBConnectionManager。getInstance(); } //========================处理 HTTP Get 请求============================ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Statement stmt=null; Connection con = connMgr。
getConnection("medicine"); if (con == null) { response。sendRedirect("/medicine/con_error。html"); return; } // ==================== 创建数据库Statement ============================= try { stmt=con。
createStatement(); } catch (Exception e) { connMgr。freeConnection("medicine",con); response。sendRedirect("/medicine/stmt_error。
html"); return; } //------------------------------------------------------------- long all_count=0; //存满足条件的药品总数 //===================从request中得到session====================== try{ HttpSession session = request。
getSession(false); if (session == null) { connMgr。freeConnection("medicine",con); response。sendRedirect("/medicine/session_error。
html"); return; } //----------------------------------------------------------- //======从“下一页”提交来的参数取得前页最后一条数据的药品编码======= String ll_pos=request。
getParameter("pos"); //如果pos=-1则表示要从头开始查 //----------------------------------------------------------。
答:很多原因是服务器卡或者是在维护中,如果你看到开始时服务器状态红色或者是延迟很多的话,就可能出现这种状态.如果是在维护中,则可能出现在 please try ag...详情>>