jquery ajax配合SpringMVC实现局部刷新DIV

feedback.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>  
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";

	String imgPath = request.getParameter("imgPath") == null ? ""
			: request.getParameter("imgPath").toString().trim();
	System.out.println(imgPath);
%>

<!DOCTYPE HTML>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<base href="<%=basePath%>">

<title>反馈信息</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" type="text/css"
	href="<%=basePath%>bootstrap-3.2.0-dist/css/bootstrap.css"></link>
<link rel="stylesheet"
	href="<%=basePath%>bootstrap-3.2.0-dist/css/bootstrap-theme.css"
	type="text/css"></link>

<script type="text/javascript" src="<%=basePath%>bootmetro/js/jquery-1.10.0.min.js"></script>
<script src="<%=basePath%>bootmetro/js/modernizr-2.6.2.min.js"></script>
<script type="text/javascript"
	src="<%=basePath%>js/jquery-1.11.1.min.js"></script>
<script src="<%=basePath%>bootstrap-3.2.0-dist/js/bootstrap.min.js"></script>

<style type="text/css">
.footer {
	position: absolute;
	bottom: 0;
	width: 100%;
	/*margin-left:-40px;*/
	/* Set the fixed height of the footer here */
	height: 60px;
	background-color: #2F2F2F;/*#f5f5f5;*/
}

body{
	/*padding:50px;*/
}

.footer>.container {
	padding-right: 15px;
	padding-left: 15px;
}
</style>
</head>

<body>
	<!-- Fixed navbar -->
	<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container" style="line-height:50px;">
      <div style="text-align: center;">
      	<a style="color:white;font-size: 18px;text-decoration: none">反馈信息</a>
      </div>
      
      </div>
    </nav>

	 <div class="container" style="margin-top:20px;padding:50px">
	 	<div class="row-fluid">
	 		<div id="flushDIV" class="col-xs-12 col-sm-12 col-md-12" style="box-shadow:0 0 10px #666666;border-radius:8px;">
	 			<table class="table table-hover" style="text-align: center;table-layout: fixed;">
	 				<thead>
	 				<tr>
	 					<th style="text-align: center;">邮箱地址</th>
	 					<th style="text-align: center;">设备ID</th>
	 					<th style="text-align: center;">电话号码</th>
	 					<th style="width:200px; text-align: center;">正文</th>
	 					<th style="text-align: center;">时间</th>
	 				</tr>
	 				</thead>
	 			<c:forEach items="${page.datas}" var="utcFeedback" varStatus="vs">
	 				<tr id="${utcFeedback.deviceId }">
	 					<td>${utcFeedback.email }</td>
	 					<td>${utcFeedback.deviceId }</td>
	 					<td>${utcFeedback.phoneNo }</td>
	 					<!--
	 					<td><a data-toggle="modal" data-target=".bs-example-modal-sm" href="javascript:void(0)">${utcFeedback.content }</a></td>
	 					-->
	 					<td>${utcFeedback.content }</td>
	 					<td>${utcFeedback.opTimer }</td>
	 				</tr>	
	 			</c:forEach>
	 					<tr>
	 						<td colspan="5">
	 							<c:if test="${page.totalCount > 0}">
	 								<c:choose>
	 									<c:when test="${page.pageNo == 1}">
	 										<a style="text-decoration: none">首页</a>    
	 										<a style="text-decoration: none">上一页</a>    
	 									</c:when>
	 									<c:otherwise>
	 										<a href="javascript:doPage(1);">首页</a>    
	 										<a href="javascript:doPage(${page.upPage});">上一页</a>    
	 									</c:otherwise>
	 								</c:choose>
	 								<c:choose>
	 									<c:when test="${page.pageNo == page.totalPage || page.totalPage == 0}">
	 										<a style="text-decoration: none">下一页</a>    
	 										<a style="text-decoration: none">末页</a>    
	 									</c:when>
	 									<c:otherwise>
	 										<a href="javascript:doPage(${page.nextPage});">下一页</a>    
	 										<a href="javascript:doPage(${page.totalPage});">末页</a>    
	 									</c:otherwise>
	 								</c:choose>
								
								<a style="text-decoration: none">当前第${page.pageNo}页</a>    
								<a style="text-decoration: none">共${page.totalPage}页</a>    
								</c:if>
								<a style="text-decoration: none">共${page.totalCount}条数据</a>    
	 						</td>
	 					</tr>
				</table>
	 		</div>
	 	
	 		
	 		
	 	</div>
	 </div>
	 
	<div class="footer">
		<div class="container">
		</div>
	</div>
	<script type="text/javascript">
		function doPage(n){
			$('#flushDIV').html("");
			$.ajax({
			       type:"POST",
			       url:"<%=basePath%>apps/queryFeedBackInfo.do",
			       data:{pageNo:n},
			       dataType: "html",   //返回值类型       使用json的话也可以,但是需要在JS中编写迭代的html代码,如果格式样式
			       cache:false,
			       success:function(data){
			           //var json = eval('('+msg+')');//拼接的json串
			           $('#flushDIV').html(data);
			       },
			       error:function(error){alert(error);}
			   });
		}
	</script>

</body>

</html>


conroller(具体DAO和Page类省略):

/**
	 * 显示不同页码的反馈信息
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/queryFeedBackInfo")
	public ModelAndView queryFeedBackInfo(HttpServletRequest request,HttpServletResponse response)throws Exception{
		UtcFeedbackDao utcFeedbackDao = new UtcFeedbackDao();
		int currentPage = request.getParameter("pageNo")==null?1:request.getParameter("pageNo").toString().trim()==""?1:Integer.parseInt(request.getParameter("pageNo").toString().trim());
		Pagination<UtcFeedback> page = null;//分页帮助类
		page = utcFeedbackDao.findByCondition(currentPage,pagesize);
		
		HashMap map = new HashMap();
	    map.put("page", page);
		return new ModelAndView("app/temp",map);
	}

temp.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'temp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

</head>

<body>
	<table class="table table-hover" style="text-align: center;table-layout: fixed;">
		<thead>
			<tr>
				<th style="text-align: center;">邮箱地址</th>
				<th style="text-align: center;">设备ID</th>
				<th style="text-align: center;">电话号码</th>
				<th style="width:200px; text-align: center;">正文</th>
				<th style="text-align: center;">时间</th>
			</tr>
		</thead>
		<c:forEach items="${page.datas}" var="utcFeedback" varStatus="vs">
			<tr id="${utcFeedback.deviceId }">
				<td>${utcFeedback.email }</td>
				<td>${utcFeedback.deviceId }</td>
				<td>${utcFeedback.phoneNo }</td>
				<td>${utcFeedback.content }</td>
				<td>${utcFeedback.opTimer }</td>
			</tr>
		</c:forEach>
		<tr>
			<td colspan="5"><c:if test="${page.totalCount > 0}">
					<c:choose>
						<c:when test="${page.pageNo == 1}">
							<a style="text-decoration: none">首页</a>    
	 						<a style="text-decoration: none">上一页</a>    
	 					</c:when>
						<c:otherwise>
							<a href="javascript:doPage(1);">首页</a>    
	 						<a href="javascript:doPage(${page.upPage});">上一页</a>    
	 					</c:otherwise>
					</c:choose>
					<c:choose>
						<c:when
							test="${page.pageNo == page.totalPage || page.totalPage == 0}">
							<a style="text-decoration: none">下一页</a>    
	 						<a style="text-decoration: none">末页</a>    
	 					</c:when>
						<c:otherwise>
							<a href="javascript:doPage(${page.nextPage});">下一页</a>    
	 						<a href="javascript:doPage(${page.totalPage});">末页</a>    
	 					</c:otherwise>
					</c:choose>

					<a style="text-decoration: none">当前第${page.pageNo}页</a>    
					<a style="text-decoration: none">共${page.totalPage}页</a>    
					</c:if> <a style="text-decoration: none">共${page.totalCount}条数据</a>    
			</td>
		</tr>
	</table>
</body>
</html>



<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>动漫搜索</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> var xmlhttp; function loadXMLDoc(url,cfun) { // alert("hadhfaf"); xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=cfun; xmlhttp.open("GET",url,true); xmlhttp.send(); } function myfunction(id,times) { //alert("123"); loadXMLDoc("open.jsp?id="+id+"&times="+times+"&t="+Math.random(),function() { //alert(xmlhttp.status); if(xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById(id).innerHTML=xmlhttp.responseText; } }); } </script> <% //currentPage当前显示页数 if (request.getParameter("currentPage") == null||request.getParameter("currentPage").equals("")) { pageContext.setAttribute("currentPage", new Integer(0)); } else { pageContext.setAttribute("currentPage", request .getParameter("currentPage")); } %> <sql:query var="rs" dataSource="jdbc/mysql"> select* from anime </sql:query> <!-- 得到所有记录数 --> <c:set var="resultNum"> <jsp:getProperty name="rs" property="rowCount" /> </c:set> <!-- 每页显示记录数 --> <c:set var="PerPageNum" value="3" /> </head> <style type="text/css"> body{background-color:} </style> <body> <% int perPageNum = Integer.parseInt((String) pageContext .getAttribute("PerPageNum")); int resultNum = Integer.parseInt((String) pageContext .getAttribute("resultNum")); int pageNum; //如果所有记录数除每页显示记录数没有余数-1 if((int)resultNum%perPageNum==0) pageNum = (int)(resultNum / perPageNum-1); else pageNum = (int)(resultNum / perPageNum); pageContext.setAttribute("pageNum", pageNum); %> <div style="border:1px solid #cccccc; width:1100px;margin:100px 0 0 90px"> <table style=" width:1100px;"> <tr> <td>序号</td> <td>热搜动漫</td> <td>动漫简介</td> <td>更新集数</td> <td>搜索指数</td> <td>动漫详情</td> </tr> <c:if test="${currentPage lt 0 }"><!-- 当前显示页小于0 --> <c:set var="currentPage" value="0"></c:set> </c:if> <c:if test="${currentPage gt pageNum}"><!-- 当前显示页大于总页数 --> <c:set var="currentPage" value="${pageNum }"></c:set> </c:if> <c:set var="currentPage" value="${currentPage}" scope="session" /> <!-- 循环查找记录 --> <c:forEach var="row" items="${rs.rows}" begin="${currentPage*PerPageNum}" end="${PerPageNum+currentPage*PerPageNum-1}" > <tr> <td> ${row.id }</td> <td> <img src="image/${row.image}" width="50" height="50"/></td> <td style="width:600"> ${row.introduce}</td> <td> ${row.blues} </td> <td> ${row.times }</td> <c:set var="times" value="${row.times }" scope="session" /> <td> <input type="button" value="展开" onclick="myfunction(${row.id },${row.times })"/> </td> </tr> <tr> <td colspan=6 id="${row.id}"></td> </tr> </c:forEach> </table> <div style="margin:0px 0px 0px 800px"> 总共有${pageNum+1}页-第${currentPage+1}页-<a href="index.jsp?currentPage=${currentPage-1}">上一页</a> - <a href="index.jsp?currentPage=${currentPage+1}">下一页</a> </div> </div> </body> </html>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值