dwr结合spring例子及出现的相关问题

dwr和spring结合的例子

 

applicationContext.xml文件
<bean id="Hello" class="com.zscqj.common.Hello"> </bean>

 

Java类

package com.zscqj.common;

public class Hello {

 public String say(String infor){
  return "您发送的消息是:" + infor;
 }
}

 

JSP页面:
<%@ page language="java" pageEncoding="utf-8"%>

<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/hello.js'> </script>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>这是测试dwr</title>
 <script type="text/javascript">
  function tijiao()
  { 
   var info=document.all["infor"].value;
   alert(info);
   hello.say(info,callback);
  }
  function callback(data)
  {
   document.all["con"].innerHTML=data;
  }
 </script>
  </head>
 
  <body>
   <br><br><br><br><br><br><br>
   <center>
    哈哈,看到地址没有啊!此页面的basePath是: <%=basePath%><br>
    哈哈,看到地址没有啊!此页面的path是: <%=path%><br><br><br><br>
    <input type="text" name="infor">
    <input type="button" value="看看我" οnclick="tijiao()"><br>
    提交后返回的内容如下:
    <br><font color="red">  <span id="con"></span>  </font>
    </center>
   
  </body>
</html>


web.xml文件:
<servlet>
 <servlet-name>dwr-invoker</servlet-name>
 <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
 <init-param>
  <description></description>
  <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>

 

dwr.xml文件:
<?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>
    <!-- resources not in this war file: java.util.Date --> 
    <create creator="spring" javascript="hello">
   <param name="beanName" value="Hello"/>
    </create>
  </allow>
</dwr>

配置好后,测试运行,出现如下错误:
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@1145cc
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Converter 'jdom' not loaded due to NoClassDefFoundError. This is only an problem if you wanted to use it. Cause: org/jdom/Document
INFO - Found Hibernate3 class: org.hibernate.Hibernate
INFO - Type 'org.jdom.Document' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.
INFO - Type 'org.jdom.Element' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@21e5f0
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Converter 'jdom' not loaded due to NoClassDefFoundError. This is only an problem if you wanted to use it. Cause: org/jdom/Document
INFO - Found Hibernate3 class: org.hibernate.Hibernate
INFO - Type 'org.jdom.Document' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.
INFO - Type 'org.jdom.Element' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@618b08
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Converter 'jdom' not loaded due to NoClassDefFoundError. This is only an problem if you wanted to use it. Cause: org/jdom/Document
INFO - Found Hibernate3 class: org.hibernate.Hibernate
INFO - Type 'org.jdom.Document' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.
INFO - Type 'org.jdom.Element' is not convertable due to missing converter 'jdom'. This is only an problem if you wanted to use it.

在网上找了一大堆资料,说少了jdom包,加上以下的网址的jdom-1.0.jar包
http://mirrors.ibiblio.org/pub/mirrors/maven/jdom/jars/jdom-1.0.jar
(添加相应的包,
http://www.findjar.com/jar/jdom/jars/jdom-1.0.jar.html
http://www.java2s.com/Code/Jar/Spring-Related/Downloadjsfapijar.htm)

运行还是出现错误,不过这次少了不少。错误如下:
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@adb24
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Found Hibernate3 class: org.hibernate.Hibernate
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@1f23ca4
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Found Hibernate3 class: org.hibernate.Hibernate
INFO - retrieved system configuration file: java.io.ByteArrayInputStream@9ced84
INFO - Creator 'pageflow' not loaded due to ClassNotFoundException. This is only an problem if you wanted to use it. Cause: Beehive/Weblogic Creator not available.
INFO - Found Hibernate3 class: org.hibernate.Hibernate

这个错误真麻烦,我在网上转了一圈又一圈,老是找不到错误的原因,有人说是xalan包问题,我照着做了,还是不行,可怜死我了。浪费了好几个小时,最后一次,我试着将DOCTYPE头文件换了一个,呵呵,问题居然解决了。这下晚上可以睡好觉了!以下是我正确的确良dwr.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
    "
http://www.getahead.ltd.uk/dwr/dwr10.dtd">

<dwr>
  <allow>
    <!-- resources not in this war file: java.util.Date --> 
    <create creator="spring" javascript="hello">
   <param name="beanName" value="Hello"/>
    </create>
  </allow>
</dwr>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值