ajax定时刷新页面

5 篇文章 0 订阅

1.jsp页面

用el表达式显示数据,页面为remind.jsp

<body style="width: 98%;">
		<%
			User_info ui = (User_info) session.getAttribute("userInfo");
			List<String> roleList = (List<String>) session
					.getAttribute("roleList");
		%>
		   
		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/Actionsn!getAllInPage.do'"
			class="linkBLAT"><big id="xxcount">${sysnotecount}</big>条信息公告</a>


		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/ticklingAction!findMeetingBaseInfoByUserId.do'"
			class="linkBLAT"><big id="fkcount">${meetingbaseInfoCout}</big>条反馈会议</a>


		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/receiptModelAction!findMeetByUserId.do'"
			class="linkBLAT"><big id="hzcount">${meetingReceiptCount}</big>条需要回执会议</a>


		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/voteAction!findMeetingByUserId.do'"
			class="linkBLAT"><big id="dccount">${searchCount}</big>条调查</a>


		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/Alignmenttemplate!meetinglist.do'"
			class="linkBLAT"><big id="tscount">${maCount}</big>个待调试会场</a>
		<%
					if (ui.getUserid() == 0 || "1".equals(ui.getUser_type())
					|| "2".equals(ui.getUser_type())) {
		%>

		<a href="javascript:void(0)"
			onClick="parent.main.location.href='${basepath }/Alignmenttemplate!meetingSXlist.do'"
			class="linkBLAT"><big id="shcount">${shCount}</big>条待审核双向调试</a>
		<%
		}
		%>


</body>

2.javascrip

这里使用ajax实现无刷新页面,页面为remind.jsp

<script type="text/javascript">
		function fresh() {
	var xmlHttp;
	//根据不同浏览器初始化xmlHttp
	try {
		//IE 6+
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			//FireFox
			xmlHttp = new XMLHttpRequest();
		} catch (e) {
			try {
				//IE 5.5+
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("您的浏览器不支持Ajax!");
			}
		}
	}
	xmlHttp.open("POST", "Actionmfm!freshJson.do", true);

	xmlHttp.send(null);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
		var jsonobj = eval('(' + xmlHttp.responseText + ')');
		$("#xxcount").html(jsonobj.sysnotecount);
		$("#fkcount").html(jsonobj.meetingbaseInfoCout);		
		$("#hzcount").html(jsonobj.meetingReceiptCount);		
		$("#dccount").html(jsonobj.searchCount);		
		$("#tscount").html(jsonobj.maCount);		
		$("#shcount").html(jsonobj.shCount);						
		}
	}
}
		
		setInterval(fresh,5000); //指定2分钟刷新一次
</script>

3.java方法

ajax里使用的方法

public String freshJson(){
		System.out.println("fresh开始");
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		
		User_info u = (User_info) ActionContext.getContext().getSession().get(
		"userInfo");
		int userId = u.getUserid();
		MeetingbaseInfoService infoservice = new MeetingbaseInfoService();
		//9999999999999999999
		int meetingbaseInfoCout =  modelService.findMeetingBaseInfoByUserId(u.getUserid()+"").size();
		session.setAttribute("meetingbaseInfoCout", meetingbaseInfoCout);

		meetList = modelService.findMainMeetingBaseInfoByUserId(u.getUserid()
				+ "");

		ActionContext.getContext().put("meetList", meetList);
		session.setAttribute("meetList", meetList);

		// 信息条数
		int sysnoteCount = this.sysNoticeService.getListByfour();
		System.out.println("===============sys" + sysnoteCount);
		session.setAttribute("sysnotecount", sysnoteCount);
		// 回执会议条数
		int meetingReceiptCount = this.mrms.getMeetingReceigpCount(userId);
		session.setAttribute("meetingReceiptCount", meetingReceiptCount);
		// 消息条数
		int msgCount = this.msginfoIpml.getCount(userId);
		session.setAttribute("msgCount", msgCount);
		// 获得需要调试的会议
		User_info userinfo = (User_info) request.getSession().getAttribute(
				"userInfo");
		// 需要进行调试的会议
		List malist = mad.getMeetingInfo(String.valueOf(u.getUserid()), "");
		// 需要审核的会议
		List shList = mad.getSxMeetingInfo(String.valueOf(u.getUserid()), "");
		List<Meeting_Alignment> meetingdebuglist = mas.getMeetingInfo(String
				.valueOf(userinfo.getUserid()), "");
		int searchCount = voteService.findMeetingByUserId(userId + "").size();
		session.setAttribute("searchCount", searchCount);
		session.setAttribute("sysnoticeList", sysnoticeList);
		session.setAttribute("meetingdebuglist", meetingdebuglist);
		session.setAttribute("malist", malist);
		session.setAttribute("maCount", malist.size());
		session.setAttribute("shCount", shList.size());
		session.setAttribute("shList", shList);
		String jsonStr = "{'sysnotecount':"+sysnoteCount+",'meetingbaseInfoCout':"+meetingbaseInfoCout+",'meetingReceiptCount':"+meetingReceiptCount+",'searchCount':"+searchCount+",'maCount':"+malist.size()+",'shCount':"+shList.size()+"}";
		try {
			inputStream = new ByteArrayInputStream(jsonStr.getBytes("UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return "remindjson";
	}

4.配置

<action name="Actionmfm!*" class="com.hb.action.meeting.MeetingFileManageAction"
			method="{1}">
			
			<result name="fresh">remind.jsp
			</result>
			 <result name="remindjson" type="stream">
				<param name="contentType">text/json</param>
				<param name="inputName">inputStream</param>
			</result>
</action>









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值