Configuration using the integrated annotation annotations DWR3.0 and Spring2.5

2010-11-08  来源:本站原创  分类:Web  人气:138 

Configuration using the integrated annotation annotations DWR3.0 and Spring2.5

Used here DWR3.rc1, Spring2.5 and Spring MVC

In Spring2.5, the use of a number of annotation, a new version of DWR also supports annotation, the following look at the configuration process

1. The first to write a Controller

Copy code to Java code

1. Package com.myapp.web.controller;
2.
3. Import javax.servlet.http.HttpServletRequest;
4. Import org.directwebremoting.annotations.RemoteMethod;
5. Import org.directwebremoting.annotations.RemoteProxy;
6. Import org.springframework.stereotype.Controller;
7. Import org.springframework.web.bind.annotation.RequestMapping;
8.
9. @ Controller
10. @ RemoteProxy
11. Public class UserController {
12.
13. @ RemoteMethod
14. Public String getUserName (int id) {
15. System.out.println ("user id is" + id);
16. Return "UserName:" + id;
17.}
18.
19. @ RequestMapping ("/ user / add.do")
20. Public String addUser (HttpServletRequest request) {
21. System.out.println ("this is action method");
22. Return "/ user / list.jsp";
23.}
24.}

package com.myapp.web.controller;

import javax.servlet.http.HttpServletRequest;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProxy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@ Controller
@ RemoteProxy
public class UserController {

@ RemoteMethod
public String getUserName (int id) {
System.out.println ("user id is" + id);
return "UserName:" + id;
}

@ RequestMapping ("/ user / add.do")
public String addUser (HttpServletRequest request) {
System.out.println ("this is action method");
return "/ user / list.jsp";
}
}

@ RemoteProxy annotation tells DWR, this Class is that we want exposed. @ RemoteMethod annotation tells DWR to expose the specified method, and only added RemoteMethod annotated method will be exposed, the other will not.

There can also use the @ RemoteProxy (name = "userRemote") means the specified name of the interface DWR

2. Then look at the configuration of web.xml

Copy the code Xml

1. <servlet>
2. <servlet-name> Action </ servlet-name>
3. <servlet-class> Org.springframework.web.servlet.DispatcherServlet </ servlet-class>
4. <load-on-startup> 1 </ load-on-startup>
5. </ Servlet>
6.
7. <context-param>
8. <param-name> ContextConfigLocation </ param-name>
9. <param-value> / WEB-INF/springconfig / *. xml </ param-value>
10. </ Context-param>
11.
12. <servlet-mapping>
13. <servlet-name> Action </ servlet-name>
14. <url-pattern> *. Do </ url-pattern>
15. </ Servlet-mapping>
16.
17. <servlet-mapping>
18. <servlet-name> Action </ servlet-name>
19. <url-pattern> / Dwr / * </ url-pattern>
20. </ Servlet-mapping>
21.
22. <listener>
23. <listener-class> Org.springframework.web.context.ContextLoaderListener </ listener-class>
24. </ Listener>

<servlet>
<servlet-name> action </ servlet-name>
<servlet-class> org.springframework.web.servlet.DispatcherServlet </ servlet-class>
<load-on-startup> 1 </ load-on-startup>
</ Servlet>

<context-param>
<param-name> contextConfigLocation </ param-name>
<param-value> / WEB-INF/springconfig / *. xml </ param-value>
</ Context-param>

<servlet-mapping>
<servlet-name> action </ servlet-name>
<url-pattern> *. do </ url-pattern>
</ Servlet-mapping>

<servlet-mapping>
<servlet-name> action </ servlet-name>
<url-pattern> / dwr / * </ url-pattern>
</ Servlet-mapping>

<listener>
<listener-class> org.springframework.web.context.ContextLoaderListener </ listener-class>
</ Listener>

Note that there is no use org.directwebremoting.spring.DwrSpringServlet or org.directwebremoting.servlet.DwrServlet, and please note here the dispatcher servlet using the spring to map / dwr / * request.

3. The last to see the profile for DispatcherServlet action-servlet.xml

Copy the code Xml

1. <Beans xmlns = "http://www.springframework.org/schema/beans"
2. Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
3. Xmlns: dwr = "http://www.directwebremoting.org/schema/spring-dwr"
4. Xmlns: context = "http://www.springframework.org/schema/context"
5. Xsi: schemaLocation = "http://www.springframework.org/schema/beans
6. Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
7. Http://www.springframework.org/schema/context
8. Http://www.springframework.org/schema/context/spring-context-2.5.xsd
9. Http://www.directwebremoting.org/schema/spring-dwr
10. Http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd "
11. Default-autowire = "byName">
12.
13. <context:annotation-config />
14.
15. <! - Note that additional dwr tag, is to take effect, the file header to declare namespace ->
16. <dwr:configuration />
17. <dwr:annotation-config />
18. <dwr:url-mapping />
19.
20. <! - The deployment project, please debug set to false ->
21. <dwr:controller Debug="true" />
22.
23. <! - Multiple package names separated by commas, but no spaces ->
24. <context:component-scan Base-package="com.myapp.web.controller" />
25.
26. <! - Order the smaller the value, the higher the priority ->
27. <bean>
28. <property Name="order" value="1" />
29. </ Bean>
30. <bean>
31. <property Name="order" value="2" />
32. </ Bean>
33.
34. </ Beans>

<Beans xmlns = "http://www.springframework.org/schema/beans"
xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns: dwr = "http://www.directwebremoting.org/schema/spring-dwr"
xmlns: context = "http://www.springframework.org/schema/context"
xsi: schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd "
default->

<context:annotation-config />

<! - Note that additional dwr tag, is to take effect, the file header to declare namespace ->
<dwr:configuration />
<dwr:annotation-config />
<dwr:url-mapping />

<! - Deployment project, please debug set to false ->
<dwr:controller debug="true" />

<! - Multiple package names separated by commas, but no spaces ->
<context:component-scan base-package="com.myapp.web.controller" />

<! - Order the smaller the value, the higher the priority ->
<bean>
<property name="order" value="1" />
</ Bean>
<bean>
<property name="order" value="2" />
</ Bean>

</ Beans>

The configuration is simple to explain

* <dwr:annotation-config /> Requires DWR to check with the Spring container and @ RemoteMethod @ RemoteProxy annotation class. Note that it is not going to check the Spring container outside of class.
* <dwr:url-mapping /> Requires DWR to util.js and mapped to the dwrController engine.js
* <dwr:controller Debug="true" /> defined dwrController
* <dwr:configuration /> This tag is not necessary in this case, if you want to configure the Spring container outside of class, you need it.

One last thing, DWR test page http://localhost:8080/myapp/dwr not used here.

Please use http://localhost:8080/myapp/dwr/test/YOUR-BEAN-NAME way to test your DWR interface

For example, used here http://localhost:8080/myapp/dwr/test/UserController

It OK to run test

相关文章
  • Configuration using the integrated annotation annotations DWR3.0 and Spring2.5 2010-11-08

    Configuration using the integrated annotation annotations DWR3.0 and Spring2.5 Used here DWR3.rc1, Spring2.5 and Spring MVC In Spring2.5, the use of a number of annotation, a new version of DWR also supports annotation, the following look at the conf

  • Based Annotation of Struts2.0 + Hibernate3.3 + Spring2.5 Integrated Development (turn) 2008-08-19

    Annotation-based access to our in Struts2.0 + Hibernate3.3 + Spring2.5 integrated development of the final stage, this phase of our project is mainly the introduction of Struts2's Annotation. Relative to the Hibernate with Annotation and Annotation o

  • Spring2.5 + DWR3.0 integration to achieve autocomplete 2010-07-12

    Recently, I group engaged in a logistics system, Boss Gao Ge I like google / baidu automatic query matching, the first reaction, too many examples online, and immediately return boss: be assured, and made set. Do plenty of online information, but doe

  • java annotation annotations order (partially reproduced) 2010-04-04

    This article will introduce you to one of the new features in J2SE5.0: Notes (Notes). What is a comment from this; J2SE5.0 comments predefined; how to customize the comment; how to comment on the notes and how to read the comments in the program to d

  • JSP custom tag + dwr3.0 very drop in infinite linkage 2010-04-22

    In the regular development tasks, the drop-down linkage is also common thing, but before this thing is impossible to write to write to GM, and now with this custom tag, and this had become generic. First talk about the realization of the function of

  • DWR3.0框架入门(1) -- 实现ajax 2013-11-25

    框架简介:DWR(Direct Web Remoting) 是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开发人员开发包含AJAX技术的网站.它可以允许在浏览器里的代码使用运行在WEB服务器上的JAVA函数,就像它就在浏览器里一样. 本Demo实现的基本功能: 点击jsp界面的按钮,通过DWR调用到服务器端的java代码,在控制台打印出jsp输入框中的值 Demo构建流程: 1.新建Web工程 2.导入jar包:commons-logging-x.x.x.jar

  • DWR3.0框架入门(2) -- DWR的服务器推送 2013-11-25

    在开始本节内容之前,先来了解一下什么是服务器推送技术和DWR的推送方式. 1.服务器推送技术和DWR的推送方式 传统模式的 Web 系统以客户端发出请求.服务器端响应的方式工作,服务端不能主动发送请求(消息)给客户端. 这种方式并不能满足很多现实应用的需求,譬如: 监控系统:后台硬件热插拔.LED.温度.电压发生变化: 即时通信系统:其它用户登录.发送信息: 即时报价系统:后台数据库内容发生变化: 这些应用都需要服务器能实时地将更新的信息传送到客户端,而无须客户端发出请求."服务器推"

  • DWR3.0框架入门(3) -- ScriptSession的维护及优化 2013-11-26

    1.ScriptSession使用中存在的问题 在上一节实现了服务器的推送功能,但是根据 ScriptSession的生命周期我们可以得出以下几点的问题: (1)ScriptSession不会与HttpSession同时创建 当我们访问一个页面的时候,如果是第一次访问,就会创建一个新的HttpSession,之后再访问的时候,就会保持当前的Session,即使是刷新,也能保持当前的HttpSession. 但是,ScriptSession不同,第一次访问,会创建一个ScriptSession,但

  • spring2.0 and spring2.5 and over different versions of the jar package 2010-09-28

    spring2.0 and spring2.5 and over different versions of the jar package Packaged in Spring 2.5 to Spring 2.5 in the Jar, Spring Web MVC is no longer a 'spring.jar' part of the file. Spring MVC to 'spring-webmvc.jar' and 'spring-webmvc-portlet.jar' fil

  • DWR3.0 Spring2.5 annotation integration with DwrSpringServlet and dwr: annotation-scan 2010-03-29

    Reference to a lot of information online to the process of integration dwr3 and spring combing using DwrSpringServlet and dwr3 about new features dwr: annotation-scan The first is xml <?xml version="1.0" encoding="UTF-8"?> <we

  • Run-dry statements MyEclipse integrated configurations: manual configuration in the integrated MyEclipse Report Run Dry 2010-09-09

    [Keywords] Run-dry statements; database connection pool; reportConfig; JNDI; Tomcat; MyEclipse The reason why the title of this article Use "by hand" the word is to prevailing on the network using "Run Report ForEclipse statements Chajian d

  • JPA-based integrated annotation SpringMVC 2011-05-05

    Entity class Department package com.sj.bean; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationTyp

  • Linux installation and configuration, and build a nexus PW maven3.0 2010-10-15

    First, the software is ready 1, apache-maven-3.0-bin.tar.gz 2, nexus-oss-webapp-1.8.0-bundle.tar.gz Second, maven installation configuration 1, create a maven user groups need to operate and user (if not created by root user installed) #groupadd conf

  • Hibernate Annotation annotations associated with the primary key and the many examples of 2011-08-09

    Requirements: 1. Have a User class, has the following attributes: String username; / / PK String password; Set grantedAuthority; / / one to many relationship to the Authorities 2. There is a Authorities, has the following attributes: String username;

  • Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "5" 2009-12-05

    http://www.blogjava.net/ilovezmh/archive/2008/12/28/248725.html Part V struts2 + spring2.5 + ibatis2 Integration 1.web.xml The main configuration struts2 filters and spring start <?xml version="1.0" encoding="UTF-8"?> <web-app

  • Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "1" 2009-01-21

    http://www.blogjava.net/ilovezmh/archive/2008/12/26/248565.html The first part of the overall description The framework for study and research for some time to understand and solve some problems, especially some of the Ext components, in combination,

  • Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "2" 2008-08-02

    http://www.blogjava.net/ilovezmh/archive/2008/12/27/248570.html The second part velocity1.5 template engine First studied the velocity1.5 template engine is used to automatically generate some code, we know that when the framework of a project to bui

  • Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "4" 2010-03-25

    http://www.blogjava.net/ilovezmh/archive/2008/12/27/248681.html The fourth section for the database table structure in order to automatically generate code The main principle is through JDBC's DatabaseMetaData class to obtain information about the da

  • Ext2.0 + struts2 + spring2.5 + ibatis2 + Hsqldb (Oracle) + velocity1.5 + semi-automatic "6" 2009-01-04

    Part VI automatically generated additions and deletions to change search method, and added to the configuration file Described the use of the previous velocity and access to database tables, as well as struts2 + spring2.5 + ibatis2 combination, we ca

  • struts-2.0.14 + spring-2.5.6 + hibernate-3.2.6 integration 2010-05-04

    1 jar package into struts2 jar package ognl-2.6.11.jar, struts2-core-2.0.14.jar, xwork-2.0.7.jar, commons-logging-1.0.4.jar, freemarker-2.3.8.jar, struts2-tiles-plugin- 2.0.14.jar hibernate 3.2 jar package antlr-2.7.6.jar, commons-collections-2.1.1.j