本文算是完全转载的,只是本人使用的是maven工具:
参考原文:
dwr入门:http://blog.csdn.net/Marksinoberg/article/details/55505423
精准推送:http://blog.csdn.net/pangliang_csdn/article/details/68945872
推送对象:http://blog.csdn.net/rongyongfeikai2/article/details/7778082
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.jzy</groupId>
<artifactId>dwr</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>dwr Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- dwr推送 -->
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.0-RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<finalName>dwr</finalName>
</build>
</project>
test.jsp
注意:里面引入的
/util.js,
engine.js,
可以根据以下地址中列出的地址进行引入:DwrPush.js
http://localhost:8080/项目名/dwr/ 点击页面上的DwrPush,里面又引入地址
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> <script type='text/javascript' src='/dwr/dwr/util.js'></script> <script type='text/javascript' src='/dwr/dwr/engine.js'></script> <script type='text/javascript' src='/dwr/dwr/interface/DwrPush.js'></script> <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ alert("开始"); //dwr.engine.setActiveReverseAjax(true); dwr.engine.setActiveReverseAjax(true) ; $("#send").click(function(){ var data = $("#msg").val(); DwrPush.Send(data); }); }); function callback(msg){ $("#ul").html(msg); } </script> </head> <body> <!-- <h1>test</h1> --> <ul id="ul" style="color:red;font-size:60px;"></ul> <input type="text" name="msg" id="msg" size="30