dwr 配置

1:下载dwr.jar放在 WebRoot\WEB-INF\lib

2:页面
<%@ 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/checkuser.js'></script>
       <script type='text/javascript'>
            function  check(form)
          {
         
           var id=document.getElementById("id").value;
           if(id=="new")
           {
           regUserChked(form);
           }
           else
           {
          
           RegUserChked(form);
             
           }
          }
        
        
        
        
        
        
        
        
        
        
          function regUserChked(form){ 
          
             var username= document.getElementById("username").value;
           
            
              if(username=="")
              {
            
              alert("用户名不能为空!")
           
              return false;
              }
             
              checkuser.isExist(username,showData);//showData回调函数  
              
               
           } 
          
            function RegUserChked(form){ 
           
              var id=document.getElementById("id").value;
              var username= document.getElementById("username").value;
              if(username=="")
              {
            
              alert("用户名不能为空!")
           
              return false;
              }
            
                checkuser.IsExistUpdate(username,id,ShowData);  //showData回调函数  
            }
          
          
          
          
          
          
          
          function showData(data){  
            if(data){  
              alert('该用户已被注册了!');
            }else{  
              alert('该用户未被注册了!');  
             }  
          }  
         
           function ShowData(data){  
            if(data){  
              alert('该用户已被注册了!');
            }else{  
              alert('可以更新!');  
             }  
          }  
        </script>
    </head>
    <body>
        <html:form action="/acctount" onsubmit="javascript:return Juge(this);">
            <input type="hidden" name="id"  value="<%=id%>">
            username : <html:text property="username" value="<%=Username %>" onblur="check(this)" />
<html:errors property="username"/><br/>
            password : <html:text property="password" value="<%=password %>"/>
<html:errors property="password"/><br/>

        <html:submit/><html:cancel/>
        </html:form>
    </body>
</html>




3:dwr.xml配置
      <dwr>

    <allow> 
 
    
 <!-- 直接取操作类  <create creator="new" javascript="checkuser" scope="application">
      <param name="class" value="com.henry.dao.daospring"/>
       <include method="isExist"/>
    </create>
   -->
  
   <!-- 间接取bean -->
       <create creator="spring" javascript="checkuser">
      <param name="beanName" value="accountDAO" />
         <include method="isExist"/>
         <include method="IsExistUpdate"/>
       </create>
 </allow> 
</dwr>

4:  applicationContext.xml

   <bean id="accountDAO" class="com.henry.dao.AccountDao">
   <property name="dataSource">
     <ref local="dataSource"/>
     </property>
    <property name="sqlMapClient">
    <ref bean="sqlMapClient"/>
    </property>
   
     </bean>
5:web.xml
   <servlet>
  <servlet-name>dwr-invoker</servlet-name>
  <display-name>DWR Servlet</display-name>
  <servlet-class>org.directwebremoting.servlet.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>
 <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


6:1)以上dwr通过间接spring-> applicationContext.xml的bean
<!-- 间接取bean -->
       <create creator="spring" javascript="checkuser">
      <param name="beanName" value="accountDAO" />
         <include method="isExist"/>
         <include method="IsExistUpdate"/>
       </create>


   2)如果直接取spring-> applicationContext.xml的bean
<!-- 直接取操作类  <create creator="new" javascript="checkuser" scope="application">
      <param name="class" value="com.henry.dao.daospring"/>
       <include method="isExist"/>
    </create>
   -->
 
com.henry.dao.daospring
:如下
package com.henry.dao;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import  com.henry.dto.accountDto;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class daospring {
    ApplicationContext context=new ClassPathXmlApplicationContext("com/henry/dbxml/applicationContext.xml");
    AccountDao testDAOImpl=(AccountDao)context.getBean("AccountDAO");
    public List getAccountsByName(String username)
    {
      
    
      return  testDAOImpl.getListByName(username);
    }
   
    /*
     * update check
     */
    public boolean IsExistUpdate(String username)
    {
        accountDto account=new accountDto();
        List list=this.getAccountsByName(username);
        if(list.size()==0)
        {
            return false;
        }
        else
        {
            //if(account.getId()==Integer.parseInt(id))
            //{
            //    return false;
               
            //}
            //else
            //{
                return true;
            //}
        }
    }
   
    public String getIdByName(String username,String id)
    {
        accountDto account=new accountDto();
        List list=this.getAccountsByName(username);
        if(list.size()==0)
        {
            return null;
        }
        else
        {
            return   Integer.toString(((accountDto)list.get(0)).getId()) ;
        }
       
    }
   
   
   
    public boolean IsExist(String username) { 
       
        if(testDAOImpl.isExist(username))
        {
        return true;
        }
        else
        {
            return false;
        }
      
   }
   
    //new or add   check
    public boolean isExist(String username) { 
          
        if(testDAOImpl.isExist(username))
        {
        return true;
        }
        else
        {
            return false;
        }
      
   }
   
   
    public accountDto getAccountById(String id)
    {
    return  testDAOImpl.getById(id);
    }
  
}


7:出现问题struts---->action--->findforward跳转页面------该页面dwr取spring-->applicationContext.xml的bean变成无效

posted on 2008-02-28 18:12 smallfa 阅读(558) 评论(0)  编辑  收藏 所属分类: jquery/dwr/extjs


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


网站导航:
 
<2008年2月>
272829303112
3456789
10111213141516
17181920212223
2425262728291
2345678

导航

统计

公告

smallfa
博客园
C++博客
博客生活
Blogjava
足球博客
微博
Redsaga

常用链接

留言簿(2)

随笔分类

随笔档案

文章分类

文章档案

相册

Ajax

Blogs

DB

java

Open source

ORM

Tools/Help

vedio Tech

搜索

最新评论

阅读排行榜

评论排行榜