文章标题
来源:互联网 发布:java httpclient post 编辑:程序博客网 时间:2024/06/01 09:23
基于上面的分页,继续将Servlet也贴出来
import java.io.IOException;import java.sql.SQLException;import java.util.List;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 com.gxa.bj.lg.model.UserInfo;import com.gxa.bj.lg.service.SerUserInfo;@WebServlet(name="page",urlPatterns="/page.do")public class PartPageServlet extends HttpServlet{ SerUserInfo serU = new SerUserInfo(); @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(); String Index = req.getParameter("hf"); session.setAttribute("pageIndex", Index); int pageIndex = Integer.parseInt(Index); try { List<UserInfo> list = serU.getListPage(pageIndex); req.setAttribute("list", list); req.getRequestDispatcher("partPage.jsp").forward(req, resp); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req,resp); }}
下面是测试的jsp页面(用了jstl标签)
<body> <script> function showPrve() { if(document.getElementById("hf").value=="") { document.getElementById("hf").value = 1; }else { var pageIndex = parseInt(document.getElementById("hf").value)-1; document.getElementById("hf").value = pageIndex; } document.form1.submit(); } function showNext() { if(document.getElementById("hf").value == "") { document.getElementById("hf").value = 1; }else { var pageIndex = parseInt(document.getElementById("hf").value)+1; document.getElementById("hf").value = pageIndex; } document.form1.submit(); } </script> <form method="post" name="form1" action="page.do"> <table> <tr> <td>用户名</td> <td>邮箱</td> </tr> <c:forEach items="${requestScope.list }" var="user"> <tr> <td> ${user.getUserName()} </td> <td> ${user.getUserEmail() } </td> </tr> </c:forEach> <input type="button" value="上一页" onclick="showPrve()" id="prve"/> <input type="button" value="下一页" onclick="showNext()" id="next"/> <input type="hidden" value="${sessionScope.pageIndex }" name = "hf" id="hf"/> </table> </form> </body>
1 0
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- interrupt()中断
- Oracle开发专题之:分析函数2(Rank, Dense_rank, row_number)
- 带有下拉刷新功能的Listview控件
- hdu517 Triple
- [leetcode#6]ZigZag Conversion
- 文章标题
- 【UML】RUP开发过程
- 基于Mavell Wifi模块的透传程序
- Oracle开发之:窗口函数 3( rows between unbounded preceding and current row)
- 分享个用Android Studio多渠道打包教程链接
- 大二训练第一周 C - Revolving Digits &&hdu 4333 扩展kmp
- leetcode | Search a 2D Matrix
- Spring使用Cache
- iOS 单例模式