標籤:rtu version begin ack sys load logs xsd framework
此文章是基於 搭建Jquery+SpringMVC+Spring+Hibernate+MySQL平台
一. 準備工作
1. 點擊此下載相關檔案,並把檔案放到 ims 工程對應的檔案夾下
二. jar包介紹
1. dwr-3.0.1.jar,支援 spring 4.3.4 的最低版本
三. 相關檔案介紹
1. web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.4"> <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>false</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> <load-on-startup>3</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app>
View Code
2. applicationContextSys.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.directwebremoting.org/schema/spring-dwr http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd"> <dwr:annotation-config id="dwrid"/> <dwr:annotation-scan scanRemoteProxy="true" base-package="com.ims.service.sys.impl" /></beans>
View Code
3. TestBSImpl.java
package com.ims.service.sys.impl;import org.directwebremoting.annotations.RemoteMethod;import org.directwebremoting.annotations.RemoteProxy;import com.ims.service.sys.TestBS;@RemoteProxy(name="testBS")public class TestBSImpl implements TestBS{ @RemoteMethod public String sayHello(){ return "hello!"; }}View Code
4. dwr.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>dwr訪問測試</title> <%@ include file="/common/basePath.jsp"%> </head> <body> ~~~~~~~~~~~~~~~~~~~~~~dwr訪問測試~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <br><br> <button type="button" onclick="sayHello();">你好</button> <script type="text/javascript" src="dwr/engine.js"></script> <script type="text/javascript" src="dwr/util.js"></script> <script type="text/javascript" src="dwr/interface/testBS.js"></script> <script type="text/javascript"> function sayHello(){ dwr.engine.beginBatch(); testBS.sayHello(function(value){ alert(value); }); dwr.engine.endBatch(); } </script> </body></html>View Code
四. 測試
訪問:http://localhost:8080/ims/test/dwr.do
點擊按鈕,會到訪問背景 sayHello 函數,彈出返回字串的對話方塊
spring與dwr整合實現js直接使用java代碼