<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    細(xì)心!用心!耐心!

    吾非文人,乃市井一俗人也,讀百卷書,跨江河千里,故申城一游; 一兩滴辛酸,三四年學(xué)業(yè),五六點粗墨,七八筆買賣,九十道人情。

    BlogJava 聯(lián)系 聚合 管理
      1 Posts :: 196 Stories :: 10 Comments :: 0 Trackbacks
    上一篇我主要介紹dwr的概況。這一篇我用dwr做了個可以不刷新頁面就更新的表格。
    screen.jpg
    運行環(huán)境:
    windows xp pro sp2
    j2sdk1.2.4_03
    weblogic8.1
    struts1.2.4
    開發(fā)工具eclipse3.0
    其實dwr和struts沒有什么關(guān)系,只不過最近我們項目組在用struts作東西。我就順便用把我的程序建立在Struts上。
    主要文件。
    dwr.jar--dwr的類庫包
    struts的類庫包,具體我不說了,這東西誰都知道。
    jdts0.9.jar--數(shù)據(jù)庫SQLServer的驅(qū)動程序包。
    以上jar包放在WebContent\WEB-INF\lib下
    web.xml--誰都知道這東西干嘛用的吧。
    struts-config.xml --這個也不說了。
    dwr.xml -- dwr的配置文件
    weblogic.xml -- weblogic模塊配置文件。
    還有一個struts的tld就不說了
    以上文件放在WebContent\WEB-INF下面。
    login.jsp -- 登陸界面,這里我也用到了dwr
    showtable.jsp --登陸成功會轉(zhuǎn)到這個頁面,一個ajax表格。
    showtable.js -- showtable.jsp中用到的javascript
    main.css -- 不說了
    還有 *.gif界面要到的圖片
    以上文件放在WebContent下
    剩下的就是java類了。
    LoginAction.java --Struts的Action,負(fù)責(zé)登陸
    TableAction.java --Struts的Action,負(fù)責(zé)表格內(nèi)容初始化
    UserLogic.java --負(fù)責(zé)驗證用戶
    TableRowConverter.java -- 繼承于dwr的BeanConverter,負(fù)責(zé)將一個對象轉(zhuǎn)成javascript能用的東西。
    LoginForm.java --Struts的Form,負(fù)責(zé)登陸信息
    TableModelBean.java --TableModel一部分給struts用一部分給dwr用。
    TableRowBean.java 用戶存放行信息的Bean。
    ModelOneDAO.java --隨便取的名字,有點惡(三聲)。負(fù)責(zé)從數(shù)據(jù)庫操作的。

    這個例子還需要一個數(shù)據(jù)庫,我用的是SQLServer。
    下面是建表的SQL語句。輸入數(shù)據(jù)的SQL就不貼了太長了。我會弄個源碼下載的。
    /*==============================================================*/
    /* DBMS name:      Microsoft SQL Server 2000                    */
    /* Created on:     2005-8-1 13:21:33                            */
    /*==============================================================*/


    if exists (select 1
                
    from  sysobjects
               
    where  id = object_id('AJAX_MODEL_ONE')
                
    and   type = 'U')
       
    drop table AJAX_MODEL_ONE
    go


    /*==============================================================*/
    /* Table: AJAX_MODEL_ONE                                        */
    /*==============================================================*/
    create table AJAX_MODEL_ONE (
       col1                 
    int                  not null,
       col2                 
    int                  not null,
       col3                 
    int                  not null,
       
    constraint PK_AJAX_MODEL_ONE primary key  (col1)
    )
    go
    接下來是寫業(yè)務(wù)邏輯
    Login.java
    /*
     * Created on 2005-7-29
     *
     * TODO To change the template for this generated file go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */

    package org.mstar.strutsajax.action;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.mstar.strutsajax.ajax.UserLogic;
    import org.mstar.strutsajax.form.LoginForm;

    /**
     * @author matianyi
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */

    public class LoginAction extends Action {

        
    /* (non-Javadoc)
         * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
         
    */

        
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) throws Exception 
    {
            
    if(validateUser((LoginForm)form)){
                
    return mapping.findForward("success");            
            }
     else {
                
    return mapping.findForward("failure");
            }
            
        }

        
        
    private boolean validateUser(LoginForm form){
            UserLogic userLogic 
    = new UserLogic();
            
    return userLogic.validate(form.getUsername(),form.getPassword());        
        }

    }
    UserLogic.java
    package org.mstar.strutsajax.ajax;

    /**
     * @author matianyi
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */

    public class UserLogic {
        
    public boolean validate(String username,String password){
            
    if("mty".equals(username)&&"123".equals(password)){
                
    return true;
            }
     else {
                
    return false;
            }

        }

    }

    LoginForm.java
    package org.mstar.strutsajax.form;

    import org.apache.struts.action.ActionForm;

    /**
     * @author matianyi
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */

    public class LoginForm extends ActionForm {
        
    private String username;
        
    private String password;

        
    /**
         * @return Returns the password.
         
    */

        
    public String getPassword() {
            
    return password;
        }

        
    /**
         * @param password The password to set.
         
    */

        
    public void setPassword(String password) {
            
    this.password = password;
        }

        
    /**
         * @return Returns the username.
         
    */

        
    public String getUsername() {
            
    return username;
        }

        
    /**
         * @param username The username to set.
         
    */

        
    public void setUsername(String username) {
            
    this.username = username;
        }

    }

    TableRowBean.java
    package org.mstar.strutsajax.form;


    /**
     * @author matianyi
     *
     * TODO To change the template for this generated type comment go to
     * Window - Preferences - Java - Code Style - Code Templates
     
    */

    public class TableRowBean{
        
    private String col1Value;
        
    private String col2Value;
        
    private String col3Value;
        

        
    /**
         * @return Returns the col1Value.
         
    */

        
    public String getCol1Value() {
            
    return col1Value;
        }

        
    /**
         * @param col1Value The col1Value to set.
         
    */

        
    public void setCol1Value(String col1Value) {
            
    this.col1Value = col1Value;
        }

        
    /**
         * @return Returns the col2Value.
         
    */

        
    public String getCol2Value() {
            
    return col2Value;
        }

        
    /**
         * @param col2Value The col2Value to set.
         
    */

        
    public void setCol2Value(String col2Value) {
            
    this.col2Value = col2Value;
        }

        
    /**
         * @return Returns the col3Value.
         
    */

        
    public String getCol3Value() {
            
    return col3Value;
        }

        
    /**
         * @param col3Value The col3Value to set.
         
    */

        
    public void setCol3Value(String col3Value) {
            
    this.col3Value = col3Value;
        }

    }
    上面的代碼都比較簡單,不用說大家也都知道是干什么用的。
    下面就是主要的內(nèi)容了。預(yù)知后事如何,且聽下回分解。
    posted on 2007-04-16 15:29 張金鵬 閱讀(571) 評論(1)  編輯  收藏 所屬分類: AJAX技術(shù)

    Feedback

    # re: dwr簡介--一個例子(一) 2012-11-12 16:50 67
    天通苑  回復(fù)  更多評論
      

    主站蜘蛛池模板: 日日麻批免费40分钟无码| 亚洲色图校园春色| 亚洲第一成年免费网站| 99精品视频在线观看免费播放| 亚洲中文字幕无码一区| 中文字幕在线视频免费观看| 亚洲综合久久夜AV | 九九视频高清视频免费观看| 国产国产人免费人成成免视频| 曰批全过程免费视频播放网站 | 亚洲剧情在线观看| 男女男精品网站免费观看| 无码中文字幕av免费放dvd| 亚洲av日韩av高潮潮喷无码| 色欲A∨无码蜜臀AV免费播| 久久久婷婷五月亚洲97号色 | 在线播放免费播放av片| 亚洲熟妇无码AV不卡在线播放| 中文字幕高清免费不卡视频| 在线观看亚洲成人| 日韩av无码久久精品免费| 亚洲大香伊人蕉在人依线| 久久久久久久99精品免费观看| 国产又黄又爽又猛的免费视频播放| 亚洲av成人中文无码专区| 亚洲国产精品国产自在在线| 99re6在线精品免费观看| 亚洲综合激情另类小说区| 精品亚洲永久免费精品| 亚洲国产成人九九综合| 免费成人在线观看| 亚洲AV综合永久无码精品天堂| 亚洲精品高清在线| 精品一区二区三区无码免费直播 | 亚洲精品无码少妇30P| 亚洲人成电影网站国产精品| a级成人毛片免费视频高清| 亚洲第一网站免费视频| 免费A级毛片在线播放不收费| 久久国产精品成人免费| 亚洲中文字幕久久精品无码A|