首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

ssh + dwr 不知道是bug还是什么有关问题啊

2011-12-23 
ssh + dwr 不知道是bug还是什么问题啊配置文件如下:1web.xmlwelcome-file-listwelcome-file /form/reg

ssh + dwr 不知道是bug还是什么问题啊
配置文件如下:
1   web.xml
      <welcome-file-list>
    <welcome-file> /form/register.jsp </welcome-file>
    </welcome-file-list>
 
    <servlet>
        <servlet-name> action </servlet-name>
        <servlet-class> org.apache.struts.action.ActionServlet </servlet-class>
        <init-param>
            <param-name> config </param-name>
            <param-value> /WEB-INF/struts-config.xml </param-value>
        </init-param>
        <init-param>
            <param-name> debug </param-name>
            <param-value> 3 </param-value>
        </init-param>
        <init-param>
            <param-name> detail </param-name>
            <param-value> 3 </param-value>
        </init-param>
        <load-on-startup> 0 </load-on-startup>
    </servlet>
   
    <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>
        <load-on-startup> 1 </load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name> action </servlet-name>
        <url-pattern> *.do </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
<servlet-name> dwr-invoker </servlet-name>
<url-pattern> /dwr/* </url-pattern>
    </servlet-mapping>
    <context-param>
    <param-name> contextConfigLocation </param-name>
    <param-value> /WEB-INF/applicationContext.xml </param-value>
    </context-param>


dwr.xml

    <dwr>
    <allow>
        <create   creator= "spring "   javascript= "springUser ">
            <param   name= "beanName "   value= "dynamicCheck ">
            </param>
            <include   method= "validateName "> </include>
            <param   name= "location "   value= "applicationContext.xml "> </param>  
        </create>
   
    </allow>
</dwr>
注:如果把creator改成new   和param   name   改成class程序就没有问题了




jsp   页面

<html>  
<head>
    <script   type= 'text/javascript '   src= ' <%=request.getContextPath()%> /dwr/engine.js '>   </script>
    <script   type= 'text/javascript '   src= ' <%=request.getContextPath()%> /dwr/util.js '>   </script>
    <script   type= 'text/javascript '   src= ' <%=request.getContextPath()%> /dwr/interface/springUser.js '>   </script>
     
      <script   language=JavaScript>
      function   valid()
    {
    var   name=dwr.util.getValue( "userName ")
   
    alert(name);
    springUser.validateName(name);  
     
    }
   
    function   showValue(value)
    {
   
    dwr.util.setValue( "show ",value);
   
    }
      </script>
<title> <bean:message   key= "bbs.user.register.title "/> </title>
</head>
<body>
<html:form   action= "/register ">
<bean:message   key= "bbs.user.register.validateCode "/> <html:text   property= "validateCode "/> <html:errors   property= "validateCode "/> <br/>

<bean:message   key= "bbs.user.register.name "/>

<html:text   property= "userName "   onblur= "valid() "/>

<html:errors   property= "userName "/> <span   id= "show "   style= "background:#eeffdd;   padding-left:4px;   padding-right:4px; "> </span>
<br/>
</html:form>
</html>

dwr   调用的java类

public   class   DynamicCheck   {

public   String   validateName(String   name){
String   error= "jjjjjjjjjjjjj ";
return   error;

}
}

spring   配置文件

<bean   id= "dynamicCheck "   class= "com.dwr.DynamicCheck "   >   </bean>


用了spring   就不行了老是在jsp页面中的springUser.validateName(name);
的springUser   未定义   不用spring   的bean方式   就没有问题
那位高手能帮帮小弟啊!


[解决办法]
帮顶
[解决办法]
就是啊不加spring程序是没有问题啊
这些框架兼容性怎么这么差啊

[解决办法]
?
帮顶
[解决办法]
如果这个问题解决不到大家用ssh框架的时候要慎用DWR啊!!!
[解决办法]
不会啊,我用SSH+DWR工作得好好的啊

user.xml,dwr配置文件:
<?xml version= "1.0 " encoding= "GBK "?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN " "http://www.getahead.ltd.uk/dwr/dwr20.dtd ">

<dwr>
<allow>
<!-- logoutDWR -->
<create creator= "spring " javascript= "Logout ">


<param name= "beanName " value= "logoutDWR "/>
<include method= "executeString "/>
</create>

dwr-user.xml,spring配置文件:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN "
"http://www.springframework.org/dtd/spring-beans.dtd ">
<beans>
<bean id= "logoutDWR " class= "com.aherp.voice.dwr.BusinessDWR ">
<property name= "name " value= "logout " />
</bean>

java文件:
package com.aherp.voice.dwr;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.aherp.voice.services.interfaces.IBusinessService;
import com.aherp.voice.util.SpringContextLoaderListener;

public class BusinessDWR {

private String name = null;

private String paramKey = null;

public Object executeMap(Map <String, String> requestMap, HttpServletRequest request) throws Exception{
IBusinessService businessService = (IBusinessService)SpringContextLoaderListener.getContext().getBean(name + "Service ");
return businessService.service(requestMap, request);
}

/**
* 执行单个参数的方式,单个参数以name+Param方式存放于request
* @param requestString
* @param request
* @return
* @throws Exception
*/
public Object executeString(String requestString, HttpServletRequest request) throws Exception{
Map <String, String> paramMap = new HashMap <String, String> ();
if(paramKey == null)
paramKey = name + "Param ";
paramMap.put(paramKey, requestString);
return executeMap(paramMap, request);
}

public void setName(String name) {
this.name = name;
}

public void setParamKey(String paramKey) {
this.paramKey = paramKey;
}

}

[解决办法]
忘记说了,环境是:struts1.3.5+spring2.1+hibernate3.2+dwr2.0
[解决办法]
那你看我的项目中用dwr有什么问题啊
[解决办法]
?????????
[解决办法]
因为你的dwr模块根本就没有成功加载dynamicCheck

这个 <param name= "location " value= "applicationContext.xml "> </param> 不需要
applicationContext.xml应该在web.xml的context-param里配置

[解决办法]
你可以分两步,首先,写一个action看是否能够调用到你的springBean,如果可以的话,然后再将这个springBean配置到dwr里。

只需要
<allow>
<!-- GetServerPressure -->
<create creator= "spring " javascript= "SpringBeanFunction ">
<param name= "beanName " value= "springBeanName "/>
<include method= "executeString "/>
</create>
</allow>
这样就OK了

BTW,你调用的Bean方法最后需要一个HttpServletRequest参数
[解决办法]
你调用的Bean方法最后需要一个HttpServletRequest参数
这是什么意思

热点排行