DWR实战(-)

<!--
首先下载dwr20.jar包,把包放到WEB-INF下面
修改web.xml文件
-->
	<servlet>
		<servlet-name>dwr-invoker</servlet-name>
		<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
		<init-param>
		<param-name>config</param-name>
		<param-value>/WEB-INF/dwr.xml</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>dwr-invoker</servlet-name>
		<url-pattern>/dwr/*</url-pattern>
	</servlet-mapping>
<!--
新建dwr.xml,也放到WEB-INF下面
-->
<dwr>
	<allow>
		<create creator="new" javascript="pubDao">
			<param name="class" value="com.DWRPubDao" />
			<include method="getName" />
		</create>
	</allow>
</dwr>

//新建JAVA类
public class DWRPubDao {
	public String getName(String name){
		return name+"你好";
	}
}

//回调函数
function callback(data){
	alert(data);
}
//调用JAVA的函数
function getName(){
	pubDao.getName("中国",callback);
}
//返回结果为:中国你好

你可能感兴趣的:(java,Web,xml,DWR)