1关于配置:
web.xml文件
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>
org.directwebremoting.servlet.DwrServlet
</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>scriptCompressed</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.xml文件
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="要变成的javascript名" scope="request">
<param name="class" value="类所在的位置" />
</create>
</allow>
</dwr>
2页面配置调用
<script language="javascript" src='${contextPath}/dwr/engine.js'></script>
<script language="javascript" src='${contextPath}/dwr/util.js'></script>
<script language="javascript" src='${contextPath}/dwr/interface/对应dwr.xml中配置的javascript名.js'></script>
<script language="JavaScript" type="text/javascript">
function getTermIds()
{
var brhId = document.getElementById("brhId").value;
GetTermId.getList(brhId,callBack);//调用类中的方法
}
function callBack(ret)//处理获得列表,把数据填写到option里去,让下拉菜单获得atm号
{
var selectobj = document.getElementById("termId");
selectobj.length=0;
for(var i=0;i<ret.length;i++)
{
selectobj.options[selectobj.options.length] = new Option(ret[i],ret[i]);
}
}
</script>
3类中的写法
4补充返回特殊自定义类型的写法
<convert converter="bean" match="com.dwr.TestBean">
<param name="include" value="username,password" />
</convert>
<signatures>
<![CDATA[ import java.util.List;
import com.dwr.TestClass;
import com.dwr.TestBean;
TestClass.testMethod7(List<TestBean>);
]]>
</signatures>
for(var i=0;i<data.length;i++)
{
alert(data.username);
alert(data[i].username);//this is ok
}