One of 3 ways to integrate DWR+SPRINGMVC

Source: Internet
Author: User

In the morning, I wrote a basic article of DWR, the afternoon saw Konghao teacher's dwr and SPRINGMVC integration video, I followed the hands of all kinds of ways to practice a bit, encountered some problems, record to yourself later when using DWR copy it.


Method One: Each dry, the coupling degree is low


Description: The way one encounters the least problem, can be said to be passed smoothly.

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.less Ony</groupid> <artifactId>dwr-spring01</artifactId> <version>1.0-snapshot</version
        > <packaging>war</packaging> <name>dwr-spring01</name> <properties> <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceencoding& Gt Utf-8</project.build.sourceencoding> <spring.version>4.0.3.RELEASE</spring.version> </pro
            perties> <dependencies> <dependency> <groupId>junit</groupId>
           <artifactId>junit</artifactId> <version>4.10</version> <scope>test</scope> </dependency>
            <!--Spring Dependency-<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> & Lt;/dependency> <dependency> <groupId>org.springframework</groupId> & lt;artifactid>spring-Webmvc</artifactid> <version>${spring.version}</version> </dependency>
            <!--dwr Dependent-<dependency> <groupId>org.directwebremoting</groupId> <artifactId>dwr</artifactId> <version>3.0.M1</version> </depend ency> </dependencies> <build> <plugins> <plugin> & Lt;groupid>org.apache.maven.plugins</groupid> &LT;ARTIFACTID&GT;MAVEN-COMPILER-PLUGIN&LT;/ARTIFAC tid> <version>3.1</version> <configuration> <s Ource>1.7</source> <target>1.7</target> <compilerarguments > <!--endorseddirs< directory > The location of the standard path for overwriting signatures--<endorseddirs&gt ; ${endorsed.dir}</endorseddirs> </compilerArguments> </configuration> </plugi N> <plugin> <groupId>org.apache.maven.plugins</groupId> & Lt;artifactid>maven-war-plugin</artifactid> <version>2.3</version> &L T;configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </ configuration> </plugin> <plugin> &LT;GROUPID&GT;ORG.APACHE.MAVEN.P Lugins</groupid> <artifactId>maven-dependency-plugin</artifactId> <ve
                        Rsion>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</artifa Ctid> <version>7.0</version> <ty Pe>jar</type> </artifactItem> </artifactitem s> </configuration> </execution> </execution
                S> </plugin> <!--jetty Server--<plugin> <groupid>org.morTbay.jetty</groupid> <artifactId>jetty-maven-plugin</artifactId> <ver Sion>8.1.16.v20140903</version> <configuration> <scanintervalseconds >10</scanIntervalSeconds> <webApp> <contextpath>/dwr-spri
                        Ng01</contextpath> </webApp> <connectors> <connector implementation= "Org.eclipse.jetty.server.nio.SelectChannelConnector" > <p
                        Ort>8801</port> <maxIdleTime>60000</maxIdleTime> </connector> </connectors> </configuration> </plugin&
            
            Gt <!--packaged plug-in to zip the Web into a zipped package--<plugin> <groupid>org.apache.maven.plugins</gRoupid> <artifactId>maven-assembly-plugin</artifactId> &LT;VERSION&GT;2.4&L t;/version> <configuration> <descriptors> <d Escriptor>assembly.xml</descriptor> </descriptors> &LT;/CONFIGURATION&G
                T
                        <executions> <!--packaged when MVN package is executed--<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 "> <!--Create a spring listener--<listener> <listen Er-class>org.springframework.web.context.contextloaderlistener</listener-class> </listener> <! --Spring's listener can use this context parameter to get Beans.xml's location-<context-param> <param-name>contextconfiglocation& lt;/param-name> <param-value>classpath*:beans.xml</param-value> </context-param> &L T;servlet> <servlet-name>dispatcher</servlet-name> <servlet-class>org.springframework .web.servlet.dispatcherservlet</servlet-class> </servlet> <servlet-mapping> <servlet-
     Name>dispatcher</servlet-name>   <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>cha Racterfilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter< /filter-class> <init-param> <param-name>encoding</param-name> <par am-value>utf-8</param-value> </init-param> </filter> <filter-mapping> & Lt;filter-name>characterfilter</filter-name> <url-pattern>/*</url-pattern> </filter-ma pping> <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>
    Org.directwebremoting.servlet.dwrservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> & lt;url-pattern>/dwr/*</url-pattern> </servlet-mapping> </web-app>
 

3. Java class

Package com.lessony.dwr.spring01.service;

Public interface Ihelloservice {public
	string SayHello (string name);
}


Package Com.lessony.dwr.spring01.service.impl;

Import Com.lessony.dwr.spring01.service.IHelloService;
Import Org.springframework.stereotype.Service;

@Service ("HelloService") Public
class HelloService implements Ihelloservice {

    @Override public
    String SayHello (String name) {
        System.out.println ("Hello" + name);
        Return "Hello:" +name;
    }

}

4. Configuring DWR, configuring in Dwr-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" xsi:schemalocation= "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.or G/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www. Springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd "> <mvc:a nnotation-driven/> <mvc:resources location= "/resources/" mapping= "/resources/**"/> <context: Component-scan base-package= "Com.lessony.dwr.spring01.controller"/> <bean class= " Org.springframework.web.servlet.view.InternalResourceViewResolver "> <property name=" prefix "Value= "/web-inf/jsp/"/> <property name= "suffix" value= ". jsp"/> </bean> <bean id= "Exceptionresolver "class=" Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver "> <property name=" Exceptionmappings "> <props> <prop key=" Com.lessony.dwr.spring01.model.MyException ">error</prop&
			Gt
 </props> </property> </bean> </beans>

There is also a spring beans.xml file

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:aop= "H Ttp://www.springframework.org/schema/aop "xmlns:context=" Http://www.springframework.org/schema/context "xmln 
        s:tx= "Http://www.springframework.org/schema/tx" xsi:schemalocation= "Http://www.springframework.org/schema/beans 
        Http://www.springframework.org/schema/beans/spring-beans-4.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-4.0.xsd Http://www.springframework.org/schema/contex T http://www.springframework.org/schema/context/spring-context-4.0.xsd Http://www.springframework.org/sche Ma/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd "> <!--Open Spring Annotation Support--&L T;context:annotation-confIG/> <!--set Spring to go to which packages to find annotation--<context:component-scan base-package= "COM.LESSONY.DWR.SPRING01"/ > </beans>

5. JSP page

<% @page contenttype= "text/html" pageencoding= "UTF-8"%> <!
DOCTYPE html>

After all edits are completed, right-click the project and select Run as ... Continue to select 7 Maven build ..., enter Jetty:run in the goals of the popup box, and click Run.

Open the browser, enter http://localhost:8801/dwr-spring01/dwr01.jsp, you can see the console output: Hello Zhang Three, and the foreground popup: Hello Zhang Three



Finally attached zip package, Link: http://download.csdn.net/detail/lxn39830435731415926/8714139

Finally complaining, with NetBeans really card ah, if it is not HTML5, JS, jquery and other hints and improve the quality of the code of the proposed programming hints, I will not use it at all. The library is bitter, I intend to use it later.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.