随笔-3  评论-0  文章-4  trackbacks-0
  2006年6月16日
用dwr实现在表单存储的功能,dwr与spring的结合使用上遇上了些问题,先把应用步骤记录下来吧:

1.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>     
        <create creator="spring" javascript="FormDataDwrUtil">   
       <param name="beanName" value="formDataDwrUtil"/>    ////配置成spring,会从spring中去找到这个bean
        </create>
   </allow> 
  
<signatures>
  <![CDATA[
  import java.util.Map; 
  ]]>
</signatures>
</dwr>

2.applicationContext.xml 片段
<bean id="formDataDwrUtil" class="com.odp.web.dwr.FormDataDwrUtil">
  <property name="formInstanceDao">
      <ref bean="formInstanceDao"/>
    </property>
 </bean>

3.web.xml  片段
 
<servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet>
        <servlet-name>dwr-invoker</servlet-name>
        <display-name>DWR Servlet</display-name>
        <description>Direct Web Remoter Servlet</description>
        <servlet-class>uk.ltd.getahead.dwr.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>

   4.jsp引用
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/FormDataDwrUtil.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/xx/js/dwr/util.js'></script> 
<!--将包中js直接拿出来用了, 做了一些修改以满足实际需求-->
<script>
   var formdata;
  function saveItem(){   
   DWRUtil.getMapValues(formdata);     //将form表单中的数据组织成map赋给formdata
    FormDataDwrUtil.saveValues(aftersave, formdata);     //调用java代码存储数据
  } 
  function aftersave(result){       
//回调方法,显示保存结果
   if( result  != null ){
    parent.setInstanceId(""+result);
    document.getElementById("msg").innerHTML = "<font color='red' size='2px'>保存成功!</font>";
    document.getElementById("save").style.display = "none";
    //document.getElementById("print").style.display="block";
    //document.getElementById("printpreview").style.display="block";
   }else{
    document.getElementById("msg").innerHTML = "<font color='red' size='2px'>保存失败!</font>";
   }
  }
  
/**
 *  根据参数找到指定的表单数据组织成map
*/
  function findItem(instanceId , tablename){          
    DWRUtil.useLoadingMessage("loading.....");
   FormDataDwrUtil.getFormData(loadItem , instanceId , tablename);
  }
/**
*回调方法,将数据填充到表单中
*/
  function loadItem(pformdata){
    formdata = pformdata;
   DWRUtil.setValues( pformdata );
   }
 
ok,能正常使用,正常保存数据,加载数据了.

问题出现了,当我改变了应用中类,weblogic会自动重载,spring重新装载数据、类,所有的东西都不受影响,dwr这里却出了问题,错误如下:
   
java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoade
rListener registered?
        at org.springframework.web.servlet.support.RequestContextUtils.getWebApp
licationContext(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletContext;)Lor
g/springframework/web/context/WebApplicationContext;(RequestContextUtils.java:83
)
        at uk.ltd.getahead.dwr.create.SpringCreator.getBeanFactory()Lorg/springf
ramework/beans/factory/BeanFactory;(SpringCreator.java:174)
        at uk.ltd.getahead.dwr.create.SpringCreator.getInstance()Ljava/lang/Obje
ct;(SpringCreator.java:131)
        at uk.ltd.getahead.dwr.create.SpringCreator.getType()Ljava/lang/Class;(S
pringCreator.java:104)
        at uk.ltd.getahead.dwr.impl.DefaultInterfaceProcessor.handle(Ljavax/serv
let/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(DefaultIn
terfaceProcessor.java:69)
        at uk.ltd.getahead.dwr.impl.DefaultProcessor.handle(Ljavax/servlet/http/
HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(DefaultProcessor.j
ava:77)
        at uk.ltd.getahead.dwr.AbstractDWRServlet.doPost(Ljavax/servlet/http/Htt
pServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(AbstractDWRServlet.ja
va:162)
        at uk.ltd.getahead.dwr.AbstractDWRServlet.doGet(Ljavax/servlet/http/Http
ServletRequest;Ljavax/servlet/http/HttpServletResponse;)V(AbstractDWRServlet.jav
a:149)
        at javax.servlet.http.HttpServlet.service(Ljavax/servlet/http/HttpServle
tRequest;Ljavax/servlet/http/HttpServletResponse;)V(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(Ljavax/servlet/ServletRequest;
Ljavax/servlet/ServletResponse;)V(HttpServlet.java:853)
        at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
()Ljava/lang/Object;(ServletStubImpl.java:1072)
        at weblogic.servlet.internal.ServletStubImpl.invokeServlet(Ljavax/servle
t/ServletRequest;Ljavax/servlet/ServletResponse;Lweblogic/servlet/internal/Filte
rChainImpl;)V(ServletStubImpl.java:465)
        at weblogic.servlet.internal.TailFilter.doFilter(Ljavax/servlet/ServletR
equest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V(TailFilter.j
ava:28)
        at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax/servlet/Ser
vletRequest;Ljavax/servlet/ServletResponse;)V(FilterChainImpl.java:27)
        at com.matrixflow.client.RequestEncoderFilter.doFilter(Ljavax/servlet/Se
rvletRequest;Ljavax/servlet/ServletResponse;Ljavax/servlet/FilterChain;)V(Reques
tEncoderFilter.java:34)
        at weblogic.servlet.internal.FilterChainImpl.doFilter(Ljavax/servlet/Ser
vletRequest;Ljavax/servlet/ServletResponse;)V(FilterChainImpl.java:27)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run()Ljava/lang/Object;(WebAppServletContext.java:6987)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Lweblogic/se
curity/subject/AbstractSubject;Ljava/security/PrivilegedAction;)Ljava/lang/Objec
t;(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(Lweblogic/security/ac
l/internal/AuthenticatedSubject;Lweblogic/security/acl/internal/AuthenticatedSub
ject;Ljava/security/PrivilegedAction;)Ljava/lang/Object;(SecurityManager.java:12
1)
        at weblogic.servlet.internal.WebAppServletContext.invokeServlet(Lweblogi
c/servlet/internal/ServletRequestImpl;Lweblogic/servlet/internal/ServletResponse
Impl;)V(WebAppServletContext.java:3892)
        at weblogic.servlet.internal.ServletRequestImpl.execute(Lweblogic/kernel
/ExecuteThread;)V(ServletRequestImpl.java:2766)
        at weblogic.kernel.ExecuteThread.execute(Lweblogic/kernel/ExecuteRequest
;)V(ExecuteThread.java:224)
        at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:183)
        at java.lang.Thread.startThreadFromVM(Ljava/lang/Thread;)V(Unknown Sourc
e)
>

在web.xml  片段里将下面这段改成Listener也不行,错误一样
 
<servlet>
        <servlet-name>context</servlet-name>
        <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>


现在的解决方法是: 重启weblogic  这肯定不是解决的问题的根本。 希望能找到问题所在.......
 
posted @ 2006-06-16 17:51 简易 阅读(622) | 评论 (0)编辑 收藏
  2006年5月19日
ajax dwr(direct web remoting)框架简介
这个从JAVA到JavaScript的远程功能方法给DWR的用户带来非常像传统的RPC机制,就像RMI或者SOAP一样,而且拥有运行在WEB上但是不需要浏览器插件的好处.
它包含两个主要的部分:允许JavaScript从WEB服务器上一个遵循了AJAX原则的Servlet(小应用程序)中获取数据.另外一方面一个JavaScript库可以帮助网站开发人员轻松地利用获取的数据来动态改变网页的内容.

http://flyfish81225.blogchina.com/4098286.html
 

http://getahead.ltd.uk/dwr/getstarted
http://getahead.ltd.uk/dwr/getstarted
dwr.xml
<!DOCTYPE dwr PUBLIC
    "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
    "http://www.getahead.ltd.uk/dwr/dwr10.dtd">

<dwr>
  <allow>
    <create creator="new" javascript="JDate">
      <param name="class" value="java.util.Date"/>
    </create>
    <create creator="new" javascript="Demo">
      <param name="class" value="your.java.Bean"/>
    </create>
  </allow>
</dwr>
defines what classes DWR can create and remote for use by Javascript
Bean类必须都有一个默认的无参构造器
DWR has a few restrictions:
  • Avoid reserved JavaScript words
  • Methods named after reserved words are automatically excluded. Most JavaScript reserved words are also Java reserved words, so you won't be having a method called "try()" anyway. However the most common gotcha is "delete()", which has special meaning from JavaScript but not Java.
  • Overloaded methods can be involved in a bit of a lottery as to which gets called, so avoid overloaded methods.



 

posted @ 2006-05-19 17:22 简易 阅读(208) | 评论 (0)编辑 收藏
  2006年5月18日
http://www.whitefrost.com/servlet/connector?file=reference/2003/06/17/libXmlRequest.html
( ajax javascript 处理xml)
没搞定,以为可以用这个js自如的处理xml,结果处处报错
var oXml = getXml("sample_data.xml");
var aNodes = selectNodes(oXml,"/sample-data-root/the-data",oXml.documentElement);
这个js里根本没有如下这个方法
  • [xml_document] = getXml(sPath): a synchronous GET request, returns null or an xml document object ,是另外一个,里面带了N多参数,试了试还是不能用,难道是js下错了?郁闷.....
  • 换了个方法来处理读入的xml文件
    文件:formdatas.xml
    <?xml version="1.0" encoding="gb2312"?>
    <formdatas>
      <data>
       <address>地址</address>                                    #text
       <productaddress>生产地址</productaddress>   #text
       <diploma>大专</diploma>                                  #select
       <type>二类|四类|三类</type>                           #checkbox
       <sex>女</sex>                                                   #radio
       <date>2005年12月31日</date>                        #text
       <memo>备注</memo>                                      #textarea   
       </data>  
    </formdatas>
    js片段:
    function updateform(xmlname,obj){  
     var url = ""+xmlname;

     if(document.implementation&&document.implementation.createDocument) {
      
      var xmldoc = document.implementation.createDocument("", "", null);
      xmldoc.onload =  handler(xmldoc, obj);
      xmldoc.load(url);
     }
     else if(window.ActiveXObject) {
      
      var xmldoc = new ActiveXObject("Microsoft.XMLDOM");
      xmldoc.onreadystatechange = function() {
       if(xmldoc.readyState == 4) handler(xmldoc, obj);
      }
      xmldoc.load(url);
     }
    }

    function handler(xmldoc, obj) {
     var formdatas = xmldoc.getElementsByTagName("data")[0]; 
     for (var i=0;i<obj.length ;i++ ){
       e=obj[i];     
       if (e.name != '') //表单中的e.name对应xml里的tagName,利用对应关系,将值写入表单中
       {    
        if ( e.type == 'text' || e.type == 'textarea'){     
         e.value = formdatas.getElementsByTagName(e.name)[0].firstChild.data;   
        }
        if( e.type == 'checkbox' || e.type == 'radio'){
         var temp = formdatas.getElementsByTagName(e.name)[0].firstChild.data.split("|");     
         for(var k=0; k<temp.length; k++){
          //alert( temp[k] );
          if( e.value == temp[k] ) e.checked = true;
         }
        }
        if( e.type == 'select-one' ){
         var selvalue = formdatas.getElementsByTagName(e.name)[0].firstChild.data;
         document.getElementById(e.name+"div").innerHTML="";
         document.getElementById(e.name+"div").innerHTML=selvalue;
        }

       }
     }
    }
    效果:点击"读取xml文件"按钮,将相应的值解析到文本框中,如下所示:
    aa.bmp

    posted @ 2006-05-18 19:54 简易 阅读(279) | 评论 (0)编辑 收藏
    仅列出标题