配置:
[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>标签。
[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>标签。