当前位置: 代码迷 >> Java Web开发 >> dwr 执行Browser.withAllSessions(run);错误
  详细解决方案

dwr 执行Browser.withAllSessions(run);错误

热度:898   发布时间:2016-04-16 21:26:28.0
dwr 执行Browser.withAllSessions(run);异常
使用dwr3的时候 按照网上demo,调用Browser.withAllSessions(run);出现
java.lang.NoSuchMethodError: org.directwebremoting.ServerContextFactory.get()Lorg/directwebremoting/ServerContext;

请大神帮我看看。
java代码
public void test2(){
System.out.println("");
Runnable run = new Runnable(){
            private ScriptBuffer script = new ScriptBuffer();
            public void run() {
                  //设置要调用的 js及参数
                  script.appendCall("alert","123");
                  //得到所有ScriptSession
                 Collection<ScriptSession> sessions = Browser.getTargetSessions() ;
                  //遍历每一个ScriptSession
                  for (ScriptSession scriptSession : sessions){
                        scriptSession.addScript( script);
                  }
            }
};
//执行推送
Browser.withAllSessions(run);
//Browser.withAllSessions(run) ;
}

javascript 代码
function DwrTest(){
//testDwr1.testDwr(0) ;
testDwr1.test2() ;
}

dwr配置
<dwr>
<allow>
<create creator="new" javascript="testDwr1" scope="session">
<param name="class" value="com.test.dwrTest.test"/>
</create>
</allow>
</dwr>

<!-- DWR 配置 -->
<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>
    <init-param>
      <param-name>scriptCompressed</param-name>
      <param-value>false</param-value>
    </init-param>
    <init-param>
            <param-name>allowScriptTagRemoting</param-name >
            <param-value>true </param-value>
         </init-param>
         <init-param>
   <param-name>classes</param-name>
   <param-value>java.lang.Object</param-value>
  </init-param>
  <!-- 开启反转Ajax 即所谓推技术 -->
  <init-param>
   <param-name>activeReverseAjaxEnabled</param-name>
   <param-value>true</param-value>
  </init-param>
   <init-param>
       <param-name>initApplicationScopeCreatorsAtStartup</param-name>
       <param-value>true</param-value>
     </init-param>
  <init-param>
     <param-name>maxWaitAfterWrite</param-name>
     <param-value>1000</param-value>
  </init-param>
  <!-- 对dwr scriptSession 自定义管理 
  <init-param>
   <param-name>org.directwebremoting.extend.ScriptSessionManager</param-name>
   <param-value>com.test.dwrTest.DwrScriptSessionManagerUtil</param-value>
   </init-param>-->
    <load-on-startup>1</load-on-startup>
   </servlet>

------解决思路----------------------
这个类中org.directwebremoting.ServerContextFactory没有get方法
很有可能是jar包冲突,
在eclipse里面 Ctrl+T,看一下有几个jar'包里面有同样的类,然后排除掉没有get方法所在类的jar包
  相关解决方案