前后端连接-页面本身刷新

页面本身刷新流程:在事件中写入跳转的servlet文件(get,post都行)执行逻辑判断,并获得前端的值或设置前端的值,再跳转回jps




1.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--c方法--%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<span> 登录成功</span>

<table>
    <tr>
        <th>编号</th>
        <th>id</th>
        <th>名称</th>
        <th>数量</th>
        <th>进库价格</th>
        <th>出库价格</th>
    </tr>


<%--        接收后端传来的数据--%>
<%--               遍历         名字--%>
        <c:forEach items="${stocklist}" var ="sto" varStatus="stostatus">
<%--            index当前行的下标--%>
            <%-- .current 当前这一行的数据--%>
            <tr>
                <td>${stostatus.index+1}</td>
                <td>${stostatus.current.id}</td>
                <td>${stostatus.current.goods_name}</td>
                <td>${stostatus.current.goods_num}</td>
                <td>${stostatus.current.goods_in_price}</td>
                <td>${stostatus.current.goods_out_price}</td>
            </tr>
<%--        <tr>--%>
<%--            <td>${sto.id}</td>--%>
<%--            <td>${sto.goods_name}</td>--%>
<%--            <td>${sto.goods_num}</td>--%>
<%--            <td>${sto.goods_in_price}</td>--%>
<%--            <td>${sto.goods_out_price}</td>--%>
<%--        </tr>--%>
        </c:forEach>
</table>

        <button οnclick="location.href='/ServletLG/ServletSelect?currentPage= 1'">首页</button>
        <button οnclick="location.href='/ServletLG/ServletSelect?currentPage=${currentPage-1}'">上一页</button>
        <button οnclick="location.href='/ServletLG/ServletSelect?currentPage=${currentPage+1}'">下一页</button>
        <button οnclick="location.href='/ServletLG/ServletSelect?currentPage=${maxye}'">尾页</button>




</body>
<%--<script src="../ajax/fenYe.js"></script>--%>
</html>

2.java

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        StockDao sd=new StockDao();
//    获取当前页数
    int tiaoshu=3;
//    request.getParameter("currentPage") 返回的值可能带有空格  用trim 去除前后空格
        int    currentPage_as = Integer.parseInt(request.getParameter("currentPage").trim());
        int maxPage=sd.maxPage(tiaoshu);
            if (currentPage_as<1){
                currentPage_as=1;
            }else if(currentPage_as>maxPage){
                currentPage_as=maxPage;
            }

        System.out.println("currentPage_as="+ currentPage_as);
        //首页


        System.out.println(maxPage);
//            将最大页数返回前端
        request.getSession().setAttribute("maxye",maxPage);
        List<Stock> ls2=sd.getFenYe(tiaoshu,currentPage_as);
//        回传
        request.getSession().setAttribute("stocklist",ls2);
        request.getSession().setAttribute("currentPage",currentPage_as);
        request.getRequestDispatcher("/jsp/denglutrue.jsp").forward(request,response);



    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值