Ajax Implementation of dwr

Source: Internet
Author: User

The memory is too bad. Take a note ,,,

Step 1:

Download the dwr jar package and place it in the lib folder;

Click Open Link


Step 2:

Configure DWR in web. xml;


[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> Step 3:

Create the DWR configuration file 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>

<! -- Configure the DWR form validators -->
<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>

<! -- Configure the DWR form validators -->
<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> Step 4:

Access http: // localhost: 8080/PoliceMap02/dwr, that is, add dwr to the end of your project to obtain the following resources:


[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> place the preceding Resources in the header of the page.

Step 5:

Test:

Page Submission request

[Javascript]
// Set the SMS center number
Function SetPhoneSMS (){
Var key = onlineList. options [onlineList. selectedIndex]. value;
Var num = document. getElementById ('setphonenum'). value;
Window. alert (num );
AjaxMonitor. setPhoneNum (key, num, processSMS );
}

// Set the SMS center number
Function SetPhoneSMS (){
Var key = onlineList. options [onlineList. selectedIndex]. value;
Var num = document. getElementById ('setphonenum'). value;
Window. alert (num );
AjaxMonitor. setPhoneNum (key, num, processSMS );
}
Background processing:


[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;
}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.