随笔-3  评论-0  文章-4  trackbacks-0
用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 on 2006-06-16 17:51 简易 阅读(622) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: