使用的是webwork架构
jsp页面:
js 代码
- //取得XMLHttpRequest对象
- if (window.ActiveXObject && !window.XMLHttpRequest) {
- window.XMLHttpRequest=function() {
- return new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP');
- };
- }
- <script>
- function ajax(){
- //path是取得系统路径
- path = "/pim-wms";//应用目录
- var ro = document.getElementById("historyInfo");
- var req=new XMLHttpRequest();
- if (req) {
- req.onreadystatechange=function() {
- if (req.readyState==4 ) {//判断状态,4是已发送,200已完成
- if(req.status==200){
- // alert(req.responseText);
- ro.innerHTML = req.responseText;
- ro.scrollTop = ro.scrollHeight;
- }else{
- ro.innerHTML = "数据加载错误。。。";
- }
- }
- }
- req.open('POST', path+'/ajax.action');//webwork
- req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset=utf-8');
- req.send("type="+type+"&startTime="+startTime+"&endTime="+endTime+"&username="+userName+"&friend="+friend);//发送参数如果有参数req.send("username="+user_name);用request取得
- }
- }
- //setInterval("ajax()",10000);
- </script>
xwork.xml
<action name="check" class="com.dualwin.pim.action.ValidateAction" method="ajax"/>
action:
java 代码
- public void ajax()throws IOException {
- String returnValue = "";
- //action 处理块
- if(cmd != null && cmd.equals("contact")){
- CardContactDelegate cardConBo = new CardContactDelegate();
- returnValue = cardConBo.findSameGroupName(username,nameLast);
- }else if(cmd != null && cmd.equals("cal")){
- CalMainDelegate cmm = new CalMainDelegate();
- returnValue = cmm.findSameSummary(username,summary,dtStart,dtEnd);
- }
- //设置response字符编码
- ServletActionContext.getResponse().setContentType("text/html;charset=UTF-8");
- PrintWriter pw = ServletActionContext.getResponse().getWriter();
- pw.print(returnValue);
- pw.close();
- }