最近使用开发的过程中出现了一个小问题,顺便记录一下原因和方法--资源页面
忘性太差,做个记笔、、、
第一步:
载下dwr的jar包放到lib文件夹下;
第二步:
在web.xml置配DWR;
<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
<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,获得如下资源
<script src="./dwr/engine.js"></script> <script src="./dwr/util.js"></script> <script src="./dwr/interface/AjaxMonitor"></script>
再将上述的资源放到页面的部头
第五步:
测试:
页面交提请求
//设置短信中央码号 function SetPhoneSMS(){ var key = onlineList.options[onlineList.selectedIndex].value; var num = document.getElementById('setphonenum').value; window.alert(num); AjaxMonitor.setPhoneNum(key,num,processSMS); }
后台处理:
public class MonitorAction {
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; }
文章结束给大家分享下程序员的一些笑话语录: 《诺基亚投资手机浏览器UCWEB,资金不详或控股》杯具了,好不容易养大的闺女嫁外国。(心疼是你养的吗?中国创业型公司创业初期哪个从国有银行贷到过钱?)