记性太差,做个笔记、、、
第一步:
下载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;
}