DWR学习(一)

1.把dwr对应的包
主要是
dwr.jar;(把DWR的演示war中的包,都复制到你的应用中)
另外还要xalan.jar包(这个包在DWR的演示war中未包含)
拷贝到应用的WEB-INF/lib目录下
2.修改web.xml文件,大概如下:

代码:


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<description>Direct Web Remoter Servlet</description>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>


3.编写dwr.xml文件保存到与web.xml同一目录下

代码:


<?xml version="1.0" encoding="gb2312"?>
<dwr>
<allow>
<create creator="new" javascript="Test" scope="application">
<param name="class"
value="com.ceun.Demo" />
</create>
</allow>
</dwr>


4.编写com.ceun.Demo类

代码:


package com.ceun;

public class Demo {
public String hello(){
return "你好";
}
}


5.编写jsp

代码:


<%@ page language="java" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>DWR 第一例</title>
<script type='text/javascript' src='dwr/engine.js'> </script>
<script type='text/javascript' src='dwr/interface/Test.js'></script>
<script type='text/javascript' src='dwr/util.js'> </script>
<script type="text/javascript">
function callBack(data){
alert(data);
}
</script>
</head>

<body>
<input type="Button" name="button3" value="测试" onclick="Test.hello(callBack)"/>
</body>
</html>

阅读更多
个人分类: AJAX
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

DWR学习(一)

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭