文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Struts2 Ajax 示例

Struts2 Ajax 示例

时间:2010-07-19  来源:qidaoxp

1. JavaScript

   function ajaxRequest(url){
            var xmlHttpReq;
            var response;
            try{
                xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
            }catch(e){
                try{
                    xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
                }catch(e){
                    try{
                        xmlHttpReq = new XMLHttpRequest();
                    }catch(e){}
                }
            }
            try{
                xmlHttpReq.open("POST", url, false);
                xmlHttpReq.onreadystatechange =
                        function(){
                        if(xmlHttpReq.readyState == 4){
                                if(xmlHttpReq.status == 200){
                                        response = xmlHttpReq.responseText; 
                            }else{ 
                                alert("Problem: " + xmlHttpReq.statustext); 
                            } 
                        }
                    };
                xmlHttpReq.send(null);
                if(response==null){
                        response = xmlHttpReq.responseText; 
                }
            }catch(e){}
            return response;
        }

  

2.JSP调用

var ajaxurl="<%=request.getContextPath()%>/adminDownload/doAjaxTest.action?";
                 alert(ajaxRequest(ajaxurl));

 

3.struts.xml配置

<action name="doAjaxTest" class="cots.admin.action.COTSDownloadReportAction" method="doAjaxTest">
                </action>

 

4.Action代码

   public void doAjaxTest(){
                try{
                        HttpServletResponse res = ServletActionContext.getResponse();
            PrintWriter out = res.getWriter(); 
                        out.println("get from ajax!"); 
                }catch (Exception e) {
            log.error( e.getMessage(), e);
        }
        }

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载