论坛首页 入门技术论坛

dwr helloword

浏览 2098 次
锁定老帖子 主题:dwr helloword
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-07-28  

         最近朋友托我帮他搞个dwr列子,所以帮他写了个。今天贴出来是为了方便那些还在外面找dwr列子的人看的。

1.定义一个接口。。

package com.whaccp.bean;

public interface IHello
{
 public String hello(String name);
}

2。实现接口

package com.whaccp.bean;

public class Hello implements IHello
{

 public String hello(String name)
 {
  return
String.format("%1$s : Hello World!!!!", name);
 }

}
3.dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "dwr10.dtd" >
<dwr>
 <allow>
  <create javascript="Hello" creator="new" scope="request">
   <param name="class" value="com.whaccp.bean.Hello"></param>
  </create>
 </allow>
</dwr>
4.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 <servlet>
  <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>
 </servlet>

 <servlet-mapping>
  <servlet-name>dwr-invoker</servlet-name>
  <url-pattern>/dwr/*</url-pattern>
 </servlet-mapping>
 
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>
5.index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  
  <script type='text/javascript'
   src='/DRWSamplePrj/dwr/interface/Hello.js'></script>
  <script type='text/javascript' src='/DRWSamplePrj/dwr/engine.js'></script>
  <script type='text/javascript' src='/DRWSamplePrj/dwr/util.js'></script>

  <script type="text/javascript">
   function hello(){
    //name=document.getElementById('txtName').value;
         name=$('txtName').value;
    Hello.hello(name,function(returnStr){
     $('spWord').innerHTML=returnStr;
    });
   }
  </script>

  <title>My JSP 'index.jsp' starting page</title>
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <!--
 <link rel="stylesheet" type="text/css" href="styles.css">
 -->
 </head>

 <body>
  Name:
  <input id="txtName" type="text" />
  <input type="submit" value="Hello" onclick="hello()"/>
  <br/>
  <span id="spWord"/>
 </body>
</html>

此列子需要dwr.jar包,另外版本需要的是5.5的,6.0的配置变了

  • bsf.jar (171.2 KB)
  • 下载次数: 12
  • dwr.jar (490.6 KB)
  • 下载次数: 718
  • DWR.rar (2.7 MB)
  • 下载次数: 14
   发表时间:2008-12-31  
干嘛非要定义一个接口IHello ,多余了吧
0 请登录后投票
   发表时间:2009-01-08  
养成良好的编码规范,兄弟没上班吧,呵呵
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics