1:把dwr.jar放到项目下的\WebRoot\WEB-INF\lib
2:在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>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>scriptSessionTimeout</param-name>
<param-value>3600000</param-value>
</init-param>
<init-param>
<param-name>maxCallCount</param-name>
<param-value>20</param-value>
</init-param>
<init-param>
<param-name>pollAndCometEnabled</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
3:建立一个DwrLx.java文件 在里面建立一个方法YZDwr()
4:在WebRoot/WEB-INF/中加入dwr.xml文件(每新写一个类就在里面配置一下)
文件内容为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="Dwr"> //在jsp 中调用的名字
<param name="class" value="com.dwr.DwrLx" />///要调用的类路径
</create>
/////////如果要用bean就要配置下面的
<!--<convert converter="bean" match="com.dwr.User">///////// 使用的哪个bean
<param name="include" value="userid,username" /> //////返回bean中要用到的哪个属性
</convert>--->
</allow>
</dwr>
5:jsp 中写入
<script type='text/javascript' src='/项目名/dwr/engine.js'></script>
<script type='text/javascript' src='/项目名/dwr/interface/Dwr.js'></script>
<script type="text/javascript">
function map()
{
DwrLx.YZDwr('sdfsdf',backMap);///传递参数必须上字符串,int不认识backMap调用的返回函数
}
function backMap(beans)
{
///返回map直接map.key;
alert(beans.ee)
////返回list
for(var i=0;i<beans.length;i++)
{
alert( beans[i].ee);
}
//////返回beans
alert(beans.userid+"********"+beans.username);
}
</script>
posted on 2008-06-01 17:28
毒毒 阅读(377)
评论(0) 编辑 收藏