DWR学习笔记-Hello World篇

 刚好一个项目要用ajax, 使用的产品平台使用DWR,就顺便了解一下DWR。

1. 下载DWR,首先将DWR.JAR包加到工程中
2. 在web.xml添加下面代码

     < servlet >
        
< description > Direct Web Remoter Servlet </ description >
        
< display - name > DWR Servlet </ display - name >
        
< servlet - name > dwr - invoker </ servlet - name >

        
< servlet - class >
            org.directwebremoting.servlet.DwrServlet
        
</ servlet - class >
        
< init - param >
            
< param - name > debug </ param - name >
            
< param - value > true </ param - value >
        
</ init - param >
        
< init - param >
            
< param - name > activeReverseAjaxEnabled </ param - name >
            
< param - value > true </ param - value >
        
</ init - param >
        
< init - param >
            
< param - name >
                initApplicationScopeCreatorsAtStartup
            
</ param - name >
            
< param - value > true </ param - value >
        
</ init - param >
        
< init - param >
            
< param - name > maxWaitAfterWrite </ param - name >
            
< param - value > 500 </ param - value >
        
</ init - param >
        
< init - param >
            
< param - name > crossDomainSessionSecurity </ param - name >
            
< param - value > false </ 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>

 

3. 编写HelloWorld代码类

package  helloworld;

public   class  HelloWorld {
    
public String sayHello(String username) {
        
return "hello " + username;
    }

}

4. 创建dwr.xml文件(默认在WEB-INF目录下)

<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd" >

< dwr >
  
< allow >
    
< create  creator ="new"  javascript ="service" >
          
< param  name ="class"  value ="helloworld.HelloWorld" />
    
</ create >
  
</ allow >

</ dwr >

5. 启动WEB服务器,运行http://localhost:8080/dwrdemo/dwr可以测试看看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

码农丁丁

你的认可是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值