加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax定时刷新页面

发布时间:2020-12-16 00:53:16 所属栏目:百科 来源:网络整理
导读:1.jsp页面 用el表达式显示数据,页面为remind.jsp body style="width: 98%;"%User_info ui = (User_info) session.getAttribute("userInfo");ListString roleList = (ListString) session.getAttribute("roleList");%a href="javascript:void(0)"onClick="pa

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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读