dwr 第一个示例 配置

web.xml

	<servlet>
		<servlet-name>dwr-invoker</servlet-name>
		<servlet-class>com.wxl.app.service.MyDwrServlet</servlet-class>
		<init-param>
			<param-name>debug</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>

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="service">
			<param name="class" value="com.wxl.app.service.HelloWorldService" />
		</create>
	</allow>
</dwr>

java

package com.wxl.app.service;

public class HelloWorldService {
	public String sayHello(String yourName) {
		// 可以是访问数据库的复杂代码
		return "Hello World " + yourName;
	}
}

jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'index.jsp' starting page</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<script type='text/javascript' src='/dwr/dwr/engine.js'></script>
		<script type='text/javascript' src='/dwr/dwr/interface/service.js'></script>
		<script type='text/javascript' src='/dwr/dwr/util.js'></script>
		<script type="text/javascript">
	function firstDwr() {
		service.sayHello("王星乐", callBackHello);
	}
	function callBackHello(data) {
		alert(data);
	}
</script>
	</head>

	<body>
		This is my JSP page.
		<br>
		<input type="button" name="button" value="测试" οnclick=
	firstDwr();
>
	</body>
</html>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值