码迷,mamicode.com
首页 > 其他好文 > 详细

bootstrap分页查询传递中文参数到后台(get方式提交)

时间:2017-08-26 14:21:27      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:parameter   path   ==   cti   表格   top   function   blog   logs   

<!--分页 -->
        <div style="width: 380px; margin: 0 auto; margin-top: 50px;">
            <ul class="pagination" style="text-align: center; margin-top: 10px;">
                <!-- 上一页 -->
                <!-- 判断当前页是否是第一页 -->
                <c:if test="${pageBean.currentPage==1 }">
                    <li class="disabled"><a href="javascript:void(0);"
                        aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                    </a></li>
                </c:if>
                <c:if test="${pageBean.currentPage!=1 }">
                    <li><a
                        href="${pageContext.request.contextPath }/fenYe?currentPage=${pageBean.currentPage-1}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod"
                        aria-label="Previous"> <span aria-hidden="true">&laquo;</span>
                    </a></li>
                </c:if>




                <c:forEach begin="1" end="${pageBean.totalPage }" var="page">
                    <!-- 判断当前页 -->
                    <c:if test="${pageBean.currentPage==page }">
                        <li class="active"><a href="javascript:void(0);">${page}</a></li>
                    </c:if>
                    <c:if test="${pageBean.currentPage!=page }">
                        <li><a class="test"
                            href="${pageContext.request.contextPath }/fenYe?currentPage=${page}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod">${page}</a></li>
                    </c:if>

                </c:forEach>

                <!-- 判断当前页是否是最后一页 -->
                <c:if test="${pageBean.currentPage==pageBean.totalPage }">
                    <li class="disabled"><a href="javascript:void(0);"
                        aria-label="Next"> <span aria-hidden="true">&raquo;</span>
                    </a></li>
                </c:if>
                <c:if test="${pageBean.currentPage!=pageBean.totalPage }">
                    <li><a class="test"
                        href="${pageContext.request.contextPath }/fenYe?currentPage=${pageBean.currentPage+1}&queryName=${queryName}&queryAddress=${queryAddress}&queryDate=${queryDate}&getTag=getMethod"
                        aria-label="Next"> <span aria-hidden="true">&raquo;</span>
                    </a></li>
                </c:if>

            </ul>
        </div>
        <!-- 分页结束 --> 

 

jQuery对其url进行编码:(参考JS对URL编码http://www.cnblogs.com/qlqwjy/p/7435054.html)

    $(".test").each(function() {
        var h = $(this).attr("href");
        $(this).attr({
            href : encodeURI(h)
        });
    });

 

 后台对接收的参数进行解码:

String getTag = request.getParameter("getTag");
        // 组装查询条件
        Condition condition = new Condition();

        // 组装名称
        String queryName = request.getParameter("queryName");
        // 如果是点击页号提交方式为get提交进行转码
        if (getTag != null && !"".equals(getTag.trim())) {
            queryName = new String(queryName.getBytes("iso-8859-1"), "utf-8");
        }
        if (queryName != null && !"".equals(queryName)) {
            condition.setQueryName(queryName);
            // 回显数据
            request.setAttribute("queryName", queryName);
        }

 

  上面的getTag标志是get方式提交,需要进行解码,如果为post提交不进行解码条件。

  对提交的英文与数字参数不需要进行解码。

   

 

还有一种方式是:ajax采用post方式提交,请求JSON,然后将JSON填充到表格。

         $.ajax({
            url:"${baseurl}/fenYe",
            async:true,
            type:"POST", 
date:{"currentPage":1,"queryName":"${queryName}","queryAddress":"${queryAddress}","queryDate":"${queryDate}"},
            success: function(data){
                },
            error:function(){
                alert("请求失败");
                },
            dataType:"json"
           
        }); 

 

 后台将查询到的数据转换为JSON串返回,ajax在成功的回调函数将JSON数据填入表格,关于JSON填充表格参考:

http://www.cnblogs.com/qlqwjy/p/7307514.html

 

bootstrap分页查询传递中文参数到后台(get方式提交)

标签:parameter   path   ==   cti   表格   top   function   blog   logs   

原文地址:http://www.cnblogs.com/qlqwjy/p/7435100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!