网站地图    收藏   

主页 > 前端 > css教程 >

dwr的ajax实现 - html/css语言栏目:html.css - 自学p

来源:自学PHP网    时间:2015-04-14 14:51 作者: 阅读:

[导读] 记性太差,做个笔记、、、第一步:下载dwr的jar包放到lib文件夹下;点击打开链接第二步:在web.xml配置DWR;[html]servlet servlet-namedwr-invoker/servlet-name servlet-classuk.ltd.getahead.dwr.D......

记性太差,做个笔记、、、

第一步:

下载dwr的jar包放到lib文件夹下;

点击打开链接


第二步:

在web.xml配置DWR;


[html]
<servlet> 
    <servlet-name>dwr-invoker</servlet-name> 
    <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> 
    <init-param> 
      <param-name>debug</param-name> 
      <param-value>true</param-value> 
    </init-param> 
  </servlet> 
  <servlet-mapping> 
    <servlet-name>dwr-invoker</servlet-name> 
    <url-pattern>/dwr/*</url-pattern> 
  </servlet-mapping> 

<servlet>
    <servlet-name>dwr-invoker</servlet-name>
    <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>dwr-invoker</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
  </servlet-mapping>第三步:

创建DWR配置文件dwr.xml


[html]
<dwr> 
  <allow> 
          
    <create creator="new" javascript="AjaxBean">     
      <param name="class" value="com.test.ajax.AjaxBean"/> 
    </create>--> 
     
    <create creator="new" javascript="AjaxMonitor">     
      <param name="class" value="com.anthony.struts2.action.MonitorAction"/> 
    </create> 
     
    <!-- 配置DWR表单验证器 -->     
    <create javascript="validator" creator="new"> 
        <param name="class" 
            value="org.apache.struts2.validators.DWRValidator" /> 
    </create> 
    <convert converter="bean" 
        match="com.opensymphony.xwork2.ValidationAwareSupport" /> 
  </allow> 
  <signatures> 
        <![CDATA[
        import java.util.Map;
        import org.apache.struts2.validators.DWRValidator;
    
        DWRValidator.doPost(String, String, Map<String, String>);
        ]]> 
  </signatures>   
</dwr> 

<dwr>
  <allow>
        
    <create creator="new" javascript="AjaxBean">   
      <param name="class" value="com.test.ajax.AjaxBean"/>
    </create>-->
   
    <create creator="new" javascript="AjaxMonitor">   
      <param name="class" value="com.anthony.struts2.action.MonitorAction"/>
    </create>
   
    <!-- 配置DWR表单验证器 -->   
 <create javascript="validator" creator="new">
     <param name="class"
         value="org.apache.struts2.validators.DWRValidator" />
 </create>
 <convert converter="bean"
     match="com.opensymphony.xwork2.ValidationAwareSupport" />
  </allow>
  <signatures>
     <![CDATA[
     import java.util.Map;
     import org.apache.struts2.validators.DWRValidator;
 
     DWRValidator.doPost(String, String, Map<String, String>);
     ]]>
  </signatures> 
</dwr>第四步:

访问http://localhost:8080/PoliceMap02/dwr,也就是自己项目的后面加个dwr,获取如下资源


[html]
<script src="./dwr/engine.js"></script>   
<script src="./dwr/util.js"></script>  
<script src="./dwr/interface/AjaxMonitor"></script> 

<script src="./dwr/engine.js"></script> 
<script src="./dwr/util.js"></script>
<script src="./dwr/interface/AjaxMonitor"></script>再将上述的资源放到页面的头部

第五步:

测试:

页面提交请求

[javascript]
//设置短信中心号码  
    function SetPhoneSMS(){ 
        var key = onlineList.options[onlineList.selectedIndex].value; 
        var num = document.getElementById('setphonenum').value; 
        window.alert(num); 
        AjaxMonitor.setPhoneNum(key,num,processSMS); 
    } 

//设置短信中心号码
 function SetPhoneSMS(){
  var key = onlineList.options[onlineList.selectedIndex].value;
  var num = document.getElementById('setphonenum').value;
  window.alert(num);
  AjaxMonitor.setPhoneNum(key,num,processSMS);
 }
后台处理:


[java]
<SPAN style="WHITE-SPACE: pre"> public class MonitorAction {</SPAN> 

 public class MonitorAction {[java] view plaincopyprint?public String setPhoneNum(String key,String num){ 
         
        int type = OrderSet.SMSCENTERNUM; 
        SendSetSMSCenterNumber centerNumber = new SendSetSMSCenterNumber(); 
        centerNumber.setSMSNum(num); 
        byte[] bytes = centerNumber.toBytes(); 
        HandleSend.parseOrder(type, key, bytes); 
        return null; 
    } 

public String setPhoneNum(String key,String num){
  
  int type = OrderSet.SMSCENTERNUM;
  SendSetSMSCenterNumber centerNumber = new SendSetSMSCenterNumber();
  centerNumber.setSMSNum(num);
  byte[] bytes = centerNumber.toBytes();
  HandleSend.parseOrder(type, key, bytes);
  return null;
 }

 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论