3.在web.xml中加入DWR使用能力:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<
servlet
>
<
servlet-name
> dwr-invoker </
servlet-name
>
<
servlet-class
> uk.ltd.getahead.dwr.DWRServlet</
servlet-class
>
<
init-param
>
<
param-name
> debug</
param-name
>
<
param-value
> true</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
> crossDomainSessionSecurity</
param-name
>
<
param-value
> false</
param-value
>
</
init-param
>
<
init-param
>
<
param-name
> allowScriptTagRemoting</
param-name
>
<
param-value
> true</
param-value
>
</
init-param
>
</
servlet
>
<
servlet-mapping
>
<
servlet-name
> dwr-invoker </
servlet-name
>
<
url-pattern
>/dwr/*</
url-pattern
>
</
servlet-mapping
>
|
1
2
3
4
5
6
7
8
|
package
sugar.dwr;
public
class
MessagePush {
public
void
send(String str){
System. out.println(str);
}
}
|
1
2
3
4
5
6
7
8
9
|
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<!
DOCTYPE
dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 3.0//EN" "http://getahead.org/dwr/dwr30.dtd" >
<
dwr
>
<
allow
>
<
create
creator
=
"new"
javascript
=
"messagePush"
>
<
param
name
=
"class"
>sugar.dwr.MessagePush</
param
>
</
create
>
</
allow
>
</
dwr
>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
<%@ page language= "java" import ="java.util.*" pageEncoding="UTF-8" %>
<!
DOCTYPE
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<
html
>
<
head
>
<
title
>DWR</
title
>
<
script
type
=
"text/javascript"
src
=
"js/jquery-1.8.3.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"dwr/util.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"dwr/engine.js"
></
script
>
<
script
type
=
"text/javascript"
src
=
"dwr/interface/messagePush.js"
></
script
>
</
head
>
<
body
>
<
table
border
=
"0"
>
<
tr
>
<
td
><
input
id
=
"content"
type
=
"text"
/></
td
>
<
td
><
input
id
=
"send"
type
=
"button"
value
=
"send"
/></
td
>
</
tr
>
</
table
>
<
script
type
=
"text/javascript"
>
$( "#send").click(function(){
var content = $("#content" ).val();
messagePush.send(content);
});
</
script
>
</
body
>
</
html
>
|