dwr学习5-spring与dwr整合(springmvc模式,没有加入annotation)
2015-05-27 14:13
501 查看
(1)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- 创建Spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr</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>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
(2)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"
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.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.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/**"/>
<context:component-scan base-package="org.lxp.cms.controller"/>
<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:controller id="dwrController" debug="true"/>
<dwr:configuration>
<dwr:convert type="bean" class="org.lxp.service.User"/>
</dwr:configuration>
<bean id="helloService" class="org.lxp.service.HelloService">
<dwr:remote javascript="hello">
<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>
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.lxp.cms.model.CmsException">error</prop>
</props>
</property>
</bean>
</beans>
(3)Java代码
public class HelloService implements IHelloService {
public String say(String name) {
return "hello:"+name;
}
@Override
public User load() {
return new User(1,"abc");
}
}
(4)前端
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/hello.js"></script>
<script type="text/javascript">
hello.load(function(data){
alert(data.name);
})
</script>
</head>
<body>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- 创建Spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring 的监听器可以通过这个上下文参数来获取beans.xml的位置 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:beans.xml</param-value>
</context-param>
<servlet>
<servlet-name>dwr</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dwr</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>dwr</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
</web-app>
(2)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"
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.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.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/**"/>
<context:component-scan base-package="org.lxp.cms.controller"/>
<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:controller id="dwrController" debug="true"/>
<dwr:configuration>
<dwr:convert type="bean" class="org.lxp.service.User"/>
</dwr:configuration>
<bean id="helloService" class="org.lxp.service.HelloService">
<dwr:remote javascript="hello">
<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>
<bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="org.lxp.cms.model.CmsException">error</prop>
</props>
</property>
</bean>
</beans>
(3)Java代码
public class HelloService implements IHelloService {
public String say(String name) {
return "hello:"+name;
}
@Override
public User load() {
return new User(1,"abc");
}
}
(4)前端
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/hello.js"></script>
<script type="text/javascript">
hello.load(function(data){
alert(data.name);
})
</script>
</head>
<body>
</body>
</html>
相关文章推荐
- dwr学习4-spring与dwr整合(非springmvc)
- Springmvc学习(03)-Spring && SpringMVC && MyBatis整合
- Spring整合Dwr,Cannot locate BeanDefinitionParser for element [annotation-scan]
- DWR的学习文档(Hello World,类型转换,Spring,Annotation) [摘]
- 学习整合hibernate springmvc spring的 心得(1)
- 学习整合hibernate springmvc spring的 心得(3)
- SpringMVC入门学习(三)+Spring应用(整合)
- springmvc学习笔记(31)——spring整合springmvc
- 学习SpringMVC——整合Hibernate、Spring、SpringMVC
- 【SpringMVC学习04】Spring、MyBatis和SpringMVC的整合
- springMVC学习笔记,SpringMV与web项目的整合(注解方式)
- springMVC学习笔记---day02 springMVC+spring+mybatis整合开发框架搭建
- (转)SpringMVC学习(四)——Spring、MyBatis和SpringMVC的整合
- Spring的学习--SpringMVC的四个基本注解annotation(控制层,业务层,持久层)
- SpringMVC学习(四)——Spring、MyBatis和SpringMVC的整合
- SpringMVC入门学习(三)+Spring应用(整合)
- Ajax框架之DWR学习(DWR 和Spring整合)-yellowcong
- SpringMVC入门学习(三)+Spring应用(整合)
- DWR通过Annotation与spring整合
- Spring 学习笔记(七) SpringMVC与Hibernate的整合