<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      DWR+SpringMVC整合的3種方式之二

      方式二:使用springmvc的控制器代替dwr的,加上相應(yīng)的mapping,省掉了dwr.xml文件

      說(shuō)明:dwr與spring耦合度提高,做這個(gè)例子的時(shí)候,我原來(lái)是用的spring4.0以上的版本,結(jié)果很遺憾,一直搞定不了,原因就是dwr好像還不支持spring高的版本。

      主要錯(cuò)誤如下:

      java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;

      所以沒(méi)辦法,換了spring低的版本,運(yùn)行jetty,一切ok




      1、pom.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <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/xsd/maven-4.0.0.xsd">
          <modelVersion>4.0.0</modelVersion>
      
          <groupId>com.lessony</groupId>
          <artifactId>dwr-spring02</artifactId>
          <version>1.0-SNAPSHOT</version>
          <packaging>war</packaging>
      
          <name>dwr-spring02</name>
      
          <properties>
              <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
              <spring.version>3.2.2.RELEASE</spring.version>
          </properties>
        
          <dependencies>
              <dependency>
                  <groupId>junit</groupId>
                  <artifactId>junit</artifactId>
                  <version>4.10</version>
                  <scope>test</scope>
              </dependency>
              
              <!--spring的依賴-->
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-context</artifactId>
                  <version>${spring.version}</version>
              </dependency>
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-core</artifactId>
                  <version>${spring.version}</version>
              </dependency>
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-beans</artifactId>
                  <version>${spring.version}</version>
              </dependency>
              <dependency>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-webmvc</artifactId>
                  <version>${spring.version}</version>
              </dependency>
              
              <!--dwr的依賴-->
              <dependency>
                  <groupId>org.directwebremoting</groupId>
                  <artifactId>dwr</artifactId>
                  <version>3.0.M1</version>
              </dependency>
          </dependencies>
      
          <build>
              <plugins>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <version>3.1</version>
                      <configuration>
                          <source>1.7</source>
                          <target>1.7</target>
                          <compilerArguments>
                              <!-- endorseddirs<目錄>覆蓋簽名的標(biāo)準(zhǔn)路徑的位置 -->
                              <endorseddirs>${endorsed.dir}</endorseddirs>
                          </compilerArguments>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-war-plugin</artifactId>
                      <version>2.3</version>
                      <configuration>
                          <failOnMissingWebXml>false</failOnMissingWebXml>
                      </configuration>
                  </plugin>
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-dependency-plugin</artifactId>
                      <version>2.6</version>
                      <executions>
                          <execution>
                              <phase>validate</phase>
                              <goals>
                                  <goal>copy</goal>
                              </goals>
                              <configuration>
                                  <outputDirectory>${endorsed.dir}</outputDirectory>
                                  <silent>true</silent>
                                  <artifactItems>
                                      <artifactItem>
                                          <groupId>javax</groupId>
                                          <artifactId>javaee-endorsed-api</artifactId>
                                          <version>7.0</version>
                                          <type>jar</type>
                                      </artifactItem>
                                  </artifactItems>
                              </configuration>
                          </execution>
                      </executions>
                  </plugin>
                  
                  <!--jetty服務(wù)器-->
                  <plugin>
                      <groupId>org.mortbay.jetty</groupId>
                      <artifactId>jetty-maven-plugin</artifactId>
                      <version>8.1.16.v20140903</version>
                      <configuration>
                          <scanIntervalSeconds>10</scanIntervalSeconds>
                          <webApp>
                              <contextPath>/dwr-spring02</contextPath>
                          </webApp>
                          <connectors>
                              <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                                  <port>8806</port>
                                  <maxIdleTime>60000</maxIdleTime>
                              </connector>
                          </connectors>
                      </configuration>
                  </plugin>
                  
                  <!--打包插件,把web打成zip包-->
                  <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-assembly-plugin</artifactId>
                      <version>2.4</version>
                      <configuration>
                          <descriptors>
                              <descriptor>assembly.xml</descriptor>
                          </descriptors>
                      </configuration>
                      <executions>
                          <!-- 當(dāng)執(zhí)行mvn package時(shí)才會(huì)打包 -->
                          <execution>
                              <id>make-assembly</id>
                              <phase>package</phase>
                              <goals>
                                  <goal>single</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
                  
              </plugins>
          </build>
      
      </project>
      


      2、web.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
      
          <!-- 創(chuàng)建Spring的監(jiān)聽(tīng)器 -->
          <listener>
              <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
          </listener>
          <!-- Spring 的監(jiān)聽(tīng)器可以通過(guò)這個(gè)上下文參數(shù)來(lái)獲取beans.xml的位置 -->
          <context-param>
              <param-name>contextConfigLocation</param-name>
              <param-value>classpath*:beans.xml</param-value>
          </context-param>
      	
          <servlet>
              <servlet-name>dispatcher</servlet-name>
              <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
               <init-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
              </init-param>
          </servlet>
          <servlet-mapping>
              <servlet-name>dispatcher</servlet-name>
              <url-pattern>/</url-pattern>
          </servlet-mapping>
          <filter>
              <filter-name>characterFilter</filter-name>
              <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
              <init-param>
                  <param-name>encoding</param-name>
                  <param-value>UTF-8</param-value>
              </init-param>
          </filter>
          <filter-mapping>
              <filter-name>characterFilter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
          
          <servlet-mapping>
              <servlet-name>dispatcher</servlet-name>
              <url-pattern>/dwr/*</url-pattern>
          </servlet-mapping>
           
      </web-app>
      

      3、java類(lèi)

      package com.lessony.dwr.spring02.entity;
      
      public class User {
      	private int id;
      	private String name;
      	public int getId() {
      		return id;
      	}
      	public void setId(int id) {
      		this.id = id;
      	}
      	public String getName() {
      		return name;
      	}
      	public void setName(String name) {
      		this.name = name;
      	}
      	public User() {
      	}
      	public User(int id, String name) {
      		super();
      		this.id = id;
      		this.name = name;
      	}
      }
      


      package com.lessony.dwr.spring02.service;
      
      import com.lessony.dwr.spring02.entity.User;
      
      public interface IHelloService {
      	public String sayHello(String name);
              
              public User load();
      }
      

      package com.lessony.dwr.spring02.service.impl;
      
      import com.lessony.dwr.spring02.entity.User;
      import com.lessony.dwr.spring02.service.IHelloService;
      
      public class HelloService implements IHelloService {
      
          @Override
          public String sayHello(String name) {
              System.out.println("hello " + name);
              return "hello: "+name;
          }
      
          @Override
          public User load() {
              System.out.println("load abc");
              return new User(1,"abc");
          }
      
      }
      

      4、配置dwr,在dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
              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.xsd
                  http://www.springframework.org/schema/context 
                  http://www.springframework.org/schema/context/spring-context-3.2.xsd
                  http://www.springframework.org/schema/mvc 
                  http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
                  http://www.directwebremoting.org/schema/spring-dwr
                  http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd">
      	
      	<mvc:annotation-driven/>
      	<mvc:resources location="/resources/" mapping="/resources/**"/>
         
              <!--dwr過(guò)濾-->
              <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      	  <property value="true" name="alwaysUseFullPath"></property> 
      	  <property name="mappings">
      	    <props> 
      	      <prop key="/dwr/**/*">dwrController</prop>
      	    </props>
      	 </property> 
      	</bean>
      	
              <!--dwr控制器-->
      	<dwr:controller id="dwrController" debug="true"/>
              
              <!--設(shè)置需要dwr轉(zhuǎn)化的實(shí)體類(lèi),格式為json傳輸?shù)絡(luò)sp頁(yè)面-->
      	<dwr:configuration>
      		<dwr:convert type="bean" class="com.lessony.dwr.spring02.entity.User"/>
      	</dwr:configuration>
      	
      	<bean id="helloService" class="com.lessony.dwr.spring02.service.impl.HelloService">
      		<dwr:remote javascript="hello02">
      		    <dwr:include method="load" />
      		</dwr:remote>
      	</bean>
      	
      	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      		<property name="prefix" value="/WEB-INF/jsp/"/>
      		<property name="suffix" value=".jsp"/>
      	</bean>
      </beans>
      

      <?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:p="http://www.springframework.org/schema/p"
             xmlns:aop="http://www.springframework.org/schema/aop"
             xmlns:context="http://www.springframework.org/schema/context"
             xmlns:tx="http://www.springframework.org/schema/tx"
             xsi:schemaLocation="http://www.springframework.org/schema/beans 
              http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
              http://www.springframework.org/schema/aop 
              http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
              http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context-3.2.xsd
              http://www.springframework.org/schema/tx 
              http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
       
      	<!-- 打開(kāi)Spring的Annotation支持 -->
      	<context:annotation-config />
      	<!-- 設(shè)定Spring 去哪些包中找Annotation -->
      	<context:component-scan base-package="com.lessony.dwr.spring02" />
      
      </beans>

      5、jsp文件

      <%-- 
          Document   : dwr01
          Created on : 2015-5-14, 2015-5-14 20:45:21
          Author     : Lessony
      --%>
      
      <%@page contentType="text/html" pageEncoding="UTF-8"%>
      <!DOCTYPE html>
      <html>
          <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <title>JSP Page</title>
              <script src="<%=request.getContextPath()%>/dwr/engine.js"></script>
              <script src="<%=request.getContextPath()%>/dwr/interface/hello02.js"></script>
              
              <script>            
                  hello02.load(function(data){
                      alert("mmmmmmm");
      		alert(data.name);
                  });
              </script>
          </head>
          <body>
              <h1>Hello World!</h1>
          </body>
      </html>
      

      全部編輯完成之后,,右鍵項(xiàng)目,選擇Run As... 繼續(xù)選擇7 Maven build...  ,在彈出框的Goals中輸入jetty:run ,然后點(diǎn)擊RUN運(yùn)行。

      打開(kāi)瀏覽器,輸入http://localhost:8806/dwr-spring02/dwr02.jsp,就可以看到控制臺(tái)輸出了:load abc,jsp頁(yè)面彈出了mmmmmm和彈出了用戶名:abc

      最后附上zip包,鏈接:http://download.csdn.net/detail/lxn39830435731415926/8714153

      posted @ 2015-05-17 23:22  Java夜未眠  閱讀(39)  評(píng)論(0)    收藏  舉報(bào)
      主站蜘蛛池模板: 人人爽人人爽人人片av东京热| 农村乱色一区二区高清视频| 国产成人综合久久亚洲av| 玩弄放荡人妻少妇系列| 欧美精品一产区二产区| 国产精品白浆无码流出| 欧美三级中文字幕在线观看 | 热久久这里只有精品99| 中文字幕日韩精品人妻| 内射视频福利在线观看| 中文字幕日韩人妻一区| 加勒比中文字幕无码一区| 日韩成人午夜精品久久高潮| 亚洲人成网站18禁止无码| 亚洲精品成人福利网站| 72种姿势欧美久久久久大黄蕉 | 国产 麻豆 日韩 欧美 久久| 日本边添边摸边做边爱喷水| 日韩一区在线中文字幕| 久久精品中文字幕免费| 国产成人高清亚洲综合| 久国产精品韩国三级视频| 久久综合色之久久综合| 东乡族自治县| 国产乱人伦真实精品视频| 99久久久国产精品免费无卡顿| 九九热精品免费视频| 亚洲性日韩精品一区二区| 国偷自产一区二区三区在线视频| 元朗区| 伊人久久大香线蕉综合网| 人妻中文字幕亚洲一区| 欧美综合天天夜夜久久| av午夜福利一片免费看久久| 99久久久国产精品免费无卡顿| 无码精品人妻一区二区三区湄公河 | 亚洲精品入口一区二区乱| 亚洲精品毛片一区二区| 萍乡市| 米奇亚洲国产精品思久久| 亚洲鸥美日韩精品久久|