DWR开发流程
程序员文章站
2022-06-12 18:10:11
...
(1)将下载到的dwr.zip解压
(2)将解压路径下WEB-INF/lib路径下的dwr.jar,commons-logging-1.0.4.jar复制到自己的web应用对应路径下
(3)修改web.xml文件
<servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <!--指定DWR是否处于调试状态,只有处于调试状态才有调试页面--> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/wangdwr/*</url-pattern> </servlet-mapping>
(4) 写类
(5)在WEB-INF路径下增加dwr.xml文件
<allow> <create creator="new" javascript="hello"> <param name="class" value="dwr.HelloDwr"/> </create> <create creator="new" javascript="json"> <param name="class" value="dwr.JSONShow"/> </create> <convert match="dwr.Person" converter="bean"/> <convert match="dwr.Cat" converter="object"> <param name="force" value="true"/> </convert> </allow> <signatures> <![CDATA[ import java.util.List; import dwr.HelloDwr; import dwr.Person; HelloDwr.sendListNoGeneric(List<Person>); ]]> </signatures>
(6)部署到服务器,访问http://localhost:8080/dwr/wangdwr/index.html可看到调试页面
(7)使用生成的javascript对象时要导入对应的javascript代码库:
<script type='text/javascript' src='/dwr/wangdwr/engine.js'></script>
<script type='text/javascript' src='/dwr/wangdwr/interface/hello.js'></script>
如果要使用工具还要导入相应工具库:
<script type='text/javascript' src='/dwr/wangdwr/util.js'></script>
(8)使用生成的javascript对象