dwr結合spring例子及出現的相關問題

來源:互聯網
上載者:User

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="看看我" onclick="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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.