引用
SPRING2.X后引入了@Controller的方式标注Controller,大大简化了原来的XML方式的MVC配置,不过传统的DWR配置方式,虽然可以通过SpringCreator的方式将BEAN暴露给AJAX使用,但是仍然逃不出繁杂的XML配置,通过SPRING的annotation方式,可以简化DWR和SPRING之间的配置.
web.xml
Xml代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" quality="high" flashvars="clipboard=%3C!--%20Spring%20--%3E%0A%09%3Cservlet%3E%0A%09%09%3Cservlet-name%3Espring%3C%2Fservlet-name%3E%0A%09%09%3Cservlet-class%3E%0A%09%09%09org.springframework.web.servlet.DispatcherServlet%0A%09%09%3C%2Fservlet-class%3E%0A%09%09%3Cinit-param%3E%0A%09%09%09%3Cparam-name%3EcontextConfigLocation%3C%2Fparam-name%3E%0A%09%09%09%3Cparam-value%3E%0A%09%09%09%09classpath%3Aspring%2FwebControllerContext.xml%0A%09%09%09%3C%2Fparam-value%3E%0A%09%09%3C%2Finit-param%3E%0A%09%09%3Cload-on-startup%3E1%3C%2Fload-on-startup%3E%0A%09%3C%2Fservlet%3E%0A%09%3Cservlet-mapping%3E%0A%09%09%3Cservlet-name%3Espring%3C%2Fservlet-name%3E%0A%09%09%3Curl-pattern%3E*.htm%3C%2Furl-pattern%3E%0A%09%3C%2Fservlet-mapping%3E%0A%09%3Cservlet-mapping%3E%0A%09%09%3Cservlet-name%3Espring%3C%2Fservlet-name%3E%0A%09%09%3Curl-pattern%3E%2Fdwr%2F*%3C%2Furl-pattern%3E%0A%09%3C%2Fservlet-mapping%3E%0A"></embed>
-
- <servlet>
- <servlet-name>spring</servlet-name>
- <servlet-class>
- org.springframework.web.servlet.DispatcherServlet
- </servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath:spring/webControllerContext.xml
- </param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>spring</servlet-name>
- <url-pattern>*.htm</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>spring</servlet-name>
- <url-pattern>/dwr/*</url-pattern>
- </servlet-mapping>
将DispatcherServlet配置成管理htm和dwr
webControllerContext.xml
Xml代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" quality="high" flashvars="clipboard=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%0A%3Cbeans%20xmlns%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Fbeans%22%0A%09xmlns%3Axsi%3D%22http%3A%2F%2Fwww.w3.org%2F2001%2FXMLSchema-instance%22%0A%09xmlns%3Ap%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Fp%22%0A%09xmlns%3Aaop%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Faop%22%0A%09xmlns%3Acontext%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Fcontext%22%0A%09xmlns%3Ajee%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Fjee%22%0A%09xmlns%3Atx%3D%22http%3A%2F%2Fwww.springframework.org%2Fschema%2Ftx%22%0A%09xmlns%3Adwr%3D%22http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr%22%0A%09xmlns%3Adwra%3D%22http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr-annotations%22%0A%09xsi%3AschemaLocation%3D%22%0A%09%09%09http%3A%2F%2Fwww.springframework.org%2Fschema%2Faop%20http%3A%2F%2Fwww.springframework.org%2Fschema%2Faop%2Fspring-aop-2.5.xsd%0A%09%09%09http%3A%2F%2Fwww.springframework.org%2Fschema%2Fbeans%20http%3A%2F%2Fwww.springframework.org%2Fschema%2Fbeans%2Fspring-beans-2.5.xsd%0A%09%09%09http%3A%2F%2Fwww.springframework.org%2Fschema%2Fcontext%20http%3A%2F%2Fwww.springframework.org%2Fschema%2Fcontext%2Fspring-context-2.5.xsd%0A%09%09%09http%3A%2F%2Fwww.springframework.org%2Fschema%2Fjee%20http%3A%2F%2Fwww.springframework.org%2Fschema%2Fjee%2Fspring-jee-2.5.xsd%0A%09%09%09http%3A%2F%2Fwww.springframework.org%2Fschema%2Ftx%20http%3A%2F%2Fwww.springframework.org%2Fschema%2Ftx%2Fspring-tx-2.5.xsd%0A%09%09%09http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr%0A%20%20%20%20%20%20%20%20%20%20%20%20http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr-2.0.xsd%0A%20%20%20%20%20%20%20%20%20%20%20%20http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr-annotations%0A%20%20%20%20%20%20%20%20%20%20%20%20http%3A%2F%2Fwww.directwebremoting.org%2Fschema%2Fspring-dwr-annotations.xsd%22%3E%0A%09%0A%09%3Ccontext%3Aannotation-config%2F%3E%0A%09%0A%09%3Ccontext%3Acomponent-scan%20base-package%3D%22mvc%22%20%2F%3E%0A%0A%09%3Cbean%0A%09%09class%3D%22org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping%22%20%2F%3E%0A%0A%09%3C!--%20%0A%09%09%3Cbean%0A%09%09class%3D%22org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter%22%20%2F%3E%0A%09--%3E%0A%0A%09%3Cbean%0A%09%09class%3D%22org.springframework.web.servlet.view.InternalResourceViewResolver%22%0A%09%09p%3Aprefix%3D%22%22%20p%3Asuffix%3D%22.jsp%22%20%2F%3E%0A%0A%09%3C!--%20DWR%20--%3E%0A%09%3Cdwr%3Aconfiguration%3E%0A%09%09%3Cdwr%3Aconvert%20class%3D%22mvc.User%22%20type%3D%22bean%22%20%2F%3E%0A%09%09%3Cdwr%3Asignatures%3E%0A%09%09%09%3C!%5BCDATA%5B%0A%09%09%09%09import%20java.util.Map%3B%0A%09%09%09%09%5D%5D%3E%0A%09%09%3C%2Fdwr%3Asignatures%3E%0A%09%3C%2Fdwr%3Aconfiguration%3E%0A%0A%09%3Cdwr%3Acontroller%20id%3D%22dwrController%22%20debug%3D%22true%22%20%2F%3E%0A%0A%09%3C!--%20%20New%20DWR%20capabilities--%3E%0A%09%3Cdwra%3Aurl-mapping%20%2F%3E%0A%09%3Cdwra%3Aannotation-config%20%2F%3E%0A%3C%2Fbeans%3E%0A"></embed>
- <?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:jee="http://www.springframework.org/schema/jee"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
- xmlns:dwra="http://www.directwebremoting.org/schema/spring-dwr-annotations"
- xsi:schemaLocation="
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- 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.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.directwebremoting.org/schema/spring-dwr
- http://www.directwebremoting.org/schema/spring-dwr-2.0.xsd
- http://www.directwebremoting.org/schema/spring-dwr-annotations
- http://www.directwebremoting.org/schema/spring-dwr-annotations.xsd">
-
- <context:annotation-config/>
-
- <context:component-scan base-package="mvc" />
-
- <bean
- class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
-
- <!--
- <bean
- class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
- -->
-
- <bean
- class="org.springframework.web.servlet.view.InternalResourceViewResolver"
- p:prefix="" p:suffix=".jsp" />
-
-
- <dwr:configuration>
- <dwr:convert class="mvc.User" type="bean" />
- <dwr:signatures>
- <![CDATA[
- import java.util.Map;
- ]]>
- </dwr:signatures>
- </dwr:configuration>
-
- <dwr:controller id="dwrController" debug="true" />
-
-
- <dwra:url-mapping />
- <dwra:annotation-config />
- </beans>
Java代码 <embed type="application/x-shockwave-flash" width="14" height="15" src="http://www.iteye.com/javascripts/syntaxhighlighter/clipboard_new.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" allowscriptaccess="always" quality="high" flashvars="clipboard=%40Controller(%22helloController%22)%0A%40RequestMapping(%22%2FhelloController.htm%22)%0A%40RemoteProxy(creator%20%3D%20SpringCreator.class%2C%20creatorParams%20%3D%20%40Param(name%20%3D%20%22beanName%22%2C%20value%20%3D%20%22helloController%22)%2C%20name%20%3D%20%22dwrHelloController%22)%0Apublic%20class%20Hello%20%7B%0A%09%2F**%0A%09%20*%20User%20Dao%0A%09%20*%2F%0A%09private%20UserDao%20userDao%3B%0A%0A%09%2F**%0A%09%20*%20Employee%20dao%0A%09%20*%2F%0A%09private%20EmployeeDao%20employeeDao%3B%0A%0A%09%40RemoteMethod%0A%09%40RequestMapping%0A%09public%20String%20sayHello()%20%7B%0A%09%09String%20str%20%3D%20%22hello%22%3B%0A%09%09System.out.println(str)%3B%0A%09%09return%20str%3B%0A%09%7D%0A%0A%09%40RemoteMethod%0A%09public%20User%20getUser()%20%7B%0A%09%09User%20user%20%3D%20this.getUserDao().getUser()%3B%0A%09%09user.setName(user.getName()%20%2B%20%22%20_%20%22%0A%09%09%09%09%2B%20this.getEmployeeDao().getEmployeeName())%3B%0A%09%09return%20user%3B%0A%09%7D%0A%0A%09%40RequestMapping(params%20%3D%20%22method%3DsayBye%22)%0A%09public%20ModelAndView%20sayBye()%20%7B%0A%09%09String%20str%20%3D%20%22bye%22%3B%0A%09%09System.out.println(str)%3B%0A%09%09return%20null%3B%0A%09%7D%0A%0A%09%2F%2F...%E5%BF%BD%E7%95%A5set%E5%92%8Cget%0A%7D%0A"></embed>
- @Controller("helloController")
- @RequestMapping("/helloController.htm")
- @RemoteProxy(creator = SpringCreator.class, creatorParams = @Param(name = "beanName", value = "helloController"), name = "dwrHelloController")
- public class Hello {
-
-
-
- private UserDao userDao;
-
-
-
-
- private EmployeeDao employeeDao;
-
- @RemoteMethod
- @RequestMapping
- public String sayHello() {
- font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px
分享到:
相关推荐
通过这种方式,你可以利用DWR的便捷性,实现动态的、无刷新的页面更新,同时利用Spring MVC的强大功能处理复杂的业务逻辑。记住,这只是一个基础配置,实际应用中可能需要根据项目需求进行更精细的调整。
在本文中,我们将探讨如何将Direct Web Remoting (DWR) 3.0与...通过这种方式,DWR 3.0与Spring 2.5的整合使用注解配置简化了开发流程,使得Java后端的方法可以直接在客户端JavaScript中调用,实现前后端的无缝交互。
本篇文章将详细介绍如何结合Dwr3和Spring3,利用全注解的方式进行集成与配置。 首先,我们需要理解Dwr3的基本概念。DWR3是DWR的第三个主要版本,它提供了一种简单的方法来实现在Web应用程序中调用服务器端的Java...
这可以通过在dwr.xml中添加`<dwr:annotation-config>`标签,以及在web.xml中配置DWR的Spring监听器来实现。 5. **编写前端代码**:在HTML页面中,引入DWR的JavaScript库,并使用DWR提供的API来调用服务器端的方法。...
本项目是Spring与DWR的整合实例,涵盖了三种整合方式,其中最彻底的方式是通过注解(Annotation)来实现,无需手动配置DWRSERVLET和dwr.xml文件,这使得配置更为简洁,同时也更符合现代开发的实践。 1. **Spring与...
SSH整合是指将Struts2、Spring和Hibernate这三个开源框架集成在一起,用于构建高效、灵活的Java Web应用程序。本文将详细讲解使用注解方式进行SSH整合的步骤。 首先,我们需要准备一个开发环境,这里选择了...
DWR 3与Spring的集成,可以让Spring管理DWR的bean,便于依赖注入和事务控制。 在这个集成配置中,各个组件通过注解和Spring的管理进行紧密协作。例如,Struts 2的Action类可以被Spring管理,其依赖通过注解自动注入...
3. **MVC配置**:使用`<mvc:annotation-driven>`元素启用注解驱动,让Spring自动扫描@Controller注解的类。 4. **视图解析器**:配置ViewResolver,例如`InternalResourceViewResolver`,指定前缀和后缀。 5. **...
### SpringMVC整合DWR3.0 实例详解 ...通过这种方式,我们可以利用DWR强大的功能来提高Web应用程序的响应速度和用户体验。希望本文能为您的项目带来帮助,也欢迎各位提出宝贵意见,共同学习进步。
在Demo_Spring_Dwr_Annotation这个文件名中,我们可以推断出这可能是一个包含演示Spring和DWR集成的项目,而且使用了全注解的方式来配置。以下是一些可能包含的知识点: 1. **Spring框架**: Spring是Java企业级应用...
### Struts1.x、Spring2.x、Hibernate3.x 和 DWR2.x 整合知识点解析 ...通过以上详细的配置和解释,可以有效地实现Struts1.x、Spring2.x、Hibernate3.x 和 DWR2.x 的整合,为开发者提供了一个稳定、高效的技术栈。
- **Spring MVC**:利用 Spring MVC 控制器来桥接 DWR 和业务逻辑层。 **3. DWR 与 HIBERNATE 整合说明** - **数据访问**:通过 Hibernate 处理数据库查询和更新操作。 - **对象映射**:利用 Hibernate 的对象关系...
通过上述步骤,开发者可以在Java Web项目中快速构建起一套基于Spring、Struts和Hibernate的技术栈。这种组合不仅能够提高开发效率,还能有效提升系统的可维护性和扩展性。希望本篇文章能为正在进行Java Web开发的...
在本项目实战中,我们将深入探讨如何利用"Spring 2.5 + Struts 2 + Hibernate (S2SH)"框架,结合Direct Web Remoting (DWR) 和ExtJS技术,来构建一个基于注解(Annotation)的高效Web应用程序。这个实战涵盖了三个...
* Java 高级知识:Annotation、IO 和 NIO、AIO、多线程、线程池、阻塞、非阻塞、异步网络通信、反射、动态代理 二、JDBC 编程 * SQL 基础:基础 SQL 语句、基本查询、多表查询、子查询、结果集的交、并、差运算 * ...