Spring管理DWR

配置:

[color=red]web.xml:[/color]

<!-- dwr start -->
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>classes </param-name>
<param-value>java.lang.Object</param-value>
</init-param>
<init-param>
<param-name>config-1</param-name>
<param-value>WEB-INF/dwr_base.xml</param-value>
</init-param>

<load-on-startup>100</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- dwr end -->

[color=red]dwr_base.xml:[/color]

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="spring" javascript="test" scope="application">
<param name="beanName" value="taxpayerManager" ></param>
<include method="testString" />
</create>
<!-- 返回实体SatTaxpayer -->
<convert converter="bean" match="com.itsv.oa.sattaxpayer.model.SatTaxpayer" >
<param name="include" value="remarkid,nsrsbh" />
</convert>
<!-- 返回list ,list中放入的是SatTaxpayer实体 -->
<convert converter="bean" match="java.util.List" >
<param name="list" value="com.itsv.oa.sattaxpayer.model.SatTaxpayer" />
</convert>
</allow>
</dwr>

[color=red]页面:[/color]

<%@page contentType="text/html;charset=UTF-8"%>
<html>
<script type='text/javascript' src='../dwr/interface/test.js'> </script>
<script type='text/javascript' src='../dwr/engine.js'> </script>
<script type='text/javascript' src='../dwr/util.js'> </script>
<body>
<script type="text/javascript">
function a(){
test.testString(huiDiaoString);
test.testVo(huiDiaoVo);
test.testList(huiDiaoList);
}

function huiDiaoString(str){
alert(str);
}

function huiDiaoVo(vo){
alert(vo.nsrsbh);

}

function huiDiaoList(list){
for(var i=0;i<list.length;i++){
alert(list[i].nsrmc);
}

}

</script>
<button οnclick="a()"></button>
</body>
</html>

[color=red]后台类:[/color]

public List testString(){

return "成功了!!";
}

public SatTaxpayer testVo(){

SatTaxpayer satTaxpayer = new SatTaxpayer();
satTaxpayer.setNsrmc("小明");
satTaxpayer.setNsrsbh("123123123");

return satTaxpayer ;
}

public List testList(){

List list = new ArrayList();
SatTaxpayer satTaxpayer = new SatTaxpayer();
satTaxpayer.setNsrmc("小明");
satTaxpayer.setNsrsbh("123123123");
list.add(satTaxpayer);

SatTaxpayer satTaxpayer1 = new SatTaxpayer();
satTaxpayer1.setNsrmc("诶我");
satTaxpayer1.setNsrsbh("123123123");
list.add(satTaxpayer1);
return list;
}


注意:如果List、Set或者Map中的元素均为简单类型(包括其封装类)或String、Date、数组和集合类型,则不需要<convert>标签。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值