myeclipse配置dwr

1、新建工程TestWeb,将dwr拷在TestWeb\WebRoot\WEB-INF\lib中

2、配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
	xmlns="http://java.sun.com/xml/ns/javaee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd">
	<servlet>
    	<servlet-name>dwr</servlet-name>
    	<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
	<init-param>
	<param-name>debug</param-name>
	<param-value>true</param-value>
	</init-param>
	</servlet>
	<servlet-mapping>
	<servlet-name>dwr</servlet-name>
    	<url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
</web-app>

3、配置dwr.xml

<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">  
<dwr> 
<allow>
 	<create creator="new" javascript="test"> 
		<param name="class" value="myDwr.Test" /> 
	</create> 
</allow> 
</dwr>

 4、简单的测试下

在Test中写了个sayHello方法,启动tomcat,在浏览器中输入http://localhost:8080/TestWeb/dwr

就可以看到test了,点击进入可以看到

Methods For: test(myDwr.Test)

To use this class in your javascript you will need the following script includes:

  <script type='text/javascript' src='/TestWeb/dwr/interface/test.js'></script>
  <script type='text/javascript' src='/TestWeb/dwr/engine.js'></script>

In addition there is an optional utility script:

  <script type='text/javascript' src='/TestWeb/dwr/util.js'></script>

Replies from DWR are shown with a yellow background if they are simple or in an alert box otherwise.
The inputs are evaluated as Javascript so strings must be quoted before execution.

There are 10 declared methods:

  • sayHello( );

编写jsp

 

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>
	<html>
	<body>
	 <script type='text/javascript' src='/TestWeb/dwr/interface/test.js'></script>
  	<script type='text/javascript' src='/TestWeb/dwr/engine.js'></script>
  	<script type='text/javascript' src='/TestWeb/dwr/util.js'></script>


	<script type="text/javascript">
	function myDWR()
	{
		test.sayHello("jhon",call);
	}
	function call(msg)
	{
		alert(msg);
	}
	</script>
  </head>
  
  <body>
  	<input type="button" name="buuton" value="测试" onclick="myDWR()">
  </body>
</html>

至此配置完成了

 

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

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

关闭
关闭
关闭