日期:2014-05-16  浏览次数:20660 次

JQuery Ajax与Struts2整合
1.前置条件:Struts2、Jquery脚本、不确定jar包:json-lib-2.1.jar

2.脚本:
//停止消息流
function stopMessageFlow(obj){
	if($("#queueManagerID").val() == null || $("#queueManagerID").val() == -1){
		return false;
	}else{
		
		//显示进度条;
		$(window).progressDialog.showDialog($('#queueWaiting').val());
		var dm_name=$(obj).parent("td").prev("td").prev("td").prev("td").prev("td").text();
		var eg_name=$(obj).parent("td").parent("tr").parent().children("tr:first").children("td:first").text();
		
		var qmId=$("#queueManagerID").val();
		var url=projectName+"/messageFlowManager/messageFlowManager_stopMessageFlow.action";
		var param = {
				"qmgrInfo.qmId":qmId,
				"qmgrInfo.executeGroupName":eg_name,
				"messageFlowName":dm_name,
				"requestTime":new Date().getTime()
		};
		$.getJSON(url,param,function(data){
			//取消进度条...
			$(window).progressDialog.hideDialog(); 
			
			var prefix=data.substring(0,data.indexOf(","));
			var result=data.substring(data.indexOf(",")+1);
			
			$("#errorDIVID").show();
			$("#error_msg").html(result);
			
			if(prefix=="true"){
				$("#tips_img").attr("src",success_img);
				status_img="<img height='16px' src='"+projectName+"/images/common/msgflow_stop.gif' lang='0'/>";
				
				$(obj).parent("td").prev("td").prev("td").html(status_img);
				
				//设置操作图片
				$(obj).parent("td").html($("#div_dm_stoped").html());
				
				//设置图片显示效果
				setPictureShow();
			}else{
				$("#tips_img").attr("src",error_img);
			}
			
		});
	}
}


3.Struts配置:
<!-- 配置BrokerManagerAction -->
		<action name="brokermanager_*" method="{1}" class="BrokerManagerAction">			
			<result type="json" name="ajaxSuccess">
				<param name="root">result</param>
			</result>
			<result name="input">/business/brokermanager/selectBar.jsp</result>
			<result name="selectBar">/business/brokermanager/selectBar.jsp</result>
			<result name="browseFile">/business/brokermanager/browseFile.jsp</result>
			<result name="deployBar">/business/brokermanager/deployBar.jsp</result>		
			<result name="brokerDisplayMqgrList">/business/brokermanager/brokerManager.jsp</result>
			<result name="success"  type="dispatcher">/business/queuemanager/brokerInfo.jsp</result>
			<result name="brokerAttribute" type="dispatcher">/business/brokermanager/brokerAttributeManager.jsp</result>
		</action>


4.在Action中定义一个属性result生成get、set就可以了。