dwr基于struts2和spring2.5的配置详解

本文详细介绍了如何在Web应用中集成并配置DWR框架,包括web.xml配置、struts.xml配置、spring的applicationContext.xml配置、接口编写加注解、jsp页面调用等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第一步:web.xml配置;
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.spring.DwrSpringServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

因为SSH框架集成了struts2,此处必须配置不让struts2拦截掉/dwr/*的action,需要作第二步配置。
第二步:struts.xml配置

<constant name="struts.action.excludePattern" value="/dwr/.*,/dwr/test/.*"></constant>

用以使struts不拦截/dwr/.*的请求
第三步:spring的applicationContext.xml配置
1)、增加命名空间
	xmlns:dwr="http://www.directwebremoting.org/schema/spring-dwr"
xmlns:dwra="http://www.directwebremoting.org/schema/spring-dwr-annotations"

2)、
http://www.directwebremoting.org/schema/spring-dwr
http://www.directwebremoting.org/schema/spring-dwr-3.0.xsd
http://www.directwebremoting.org/schema/spring-dwr-annotations
http://www.directwebremoting.org/schema/spring-dwr-annotations.xsd

3)、
<context:annotation-config/>
<context:component-scan base-package="com.gd.service.impl" />
<dwr:configuration />

<dwr:annotation-scan base-package="com.gd.service.impl" scanDataTransferObject="true" scanRemoteProxy="true" />

第四步:接口编写加注解:
@RemoteProxy(creator = SpringCreator.class, name = "DWRService")
public class TmEduExaminationInfoManagerImpl implements
ITmEduExaminationInfoManager


@RemoteMethod
public String queryInfo(String str){
return "hello " + str;
}

注:必须有接口及其实现类
第五步:jsp页面调用
1)、引用js
<script type='text/javascript' src='dwr/engine.js'></script> 
<script type='text/javascript' src='dwr/util.js'></script>
<script type='text/javascript' src='dwr/interface/DWRService.js'></script>

2)、JS调用
DWRService.queryInfo("你是谁",function(flag){  
if(flag){
alert(flag);
}else{
alert(flag);
}
});
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值