dwr+maven实现java和js方法互相调用,实现推送, 完整切超简单例子

这篇博客介绍了如何利用DWR(Direct Web Remoting)结合Maven,实现Java和JavaScript之间的方法调用,以及如何进行精准推送。作者通过引用并实践相关教程,提供了一个简单易懂的示例,帮助读者快速理解和应用DWR在实际项目中的推送功能。
摘要由CSDN通过智能技术生成


本文算是完全转载的,只是本人使用的是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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值