Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > struts1.1中的Lazy ActionForm
【标  题】:struts1.1中的Lazy ActionForm
【关键字】:struts1.1,Lazy,ActionForm
【来  源】:http://www.blogjava.net/terry-zj/archive/2006/03/01/33037.html

struts1.1中的Lazy ActionForm

Your Ad Here

以前我转载过一篇“介绍struts的新特性:Lazy ActionForm“
http://www.blogjava.net/terry-zj/archive/2005/12/09/23090.html
这篇文章里面介绍的方法大大较少了ActionForm中的编码工作,但是这个Lazy ActionForm在struts1.1的时候还没有。如果既要使用struts1.1又想Lazy一下那?(实际上struts1.1还是目前使用比较多的版本)
其实少量的代码就可以让普通的Form接近Lazy ActionForm的效果。
 jsp中写:
        <table align="center" border="0" width="300">
                <tr>
                    <td align="right" width="35%">
                        用户ID:
                    </td>
                    <td width="65%">
                        <html:text property="data(USER_ID)" size="20" maxlength="20" />
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        密码:
                    </td>
                    <td>
                        <html:text property="data(USER_PWD)" size="20" maxlength="10" />
                    </td>
                </tr>
                <tr>
                    <td>
                        &nbsp;&nbsp;&nbsp;
                    </td>
                    <td>
                        <html:button property="login" value="确认" onclick="submitForm();" />
                        &nbsp;&nbsp;&nbsp;
                        <html:reset value="清空" />
                    </td>
                </tr>
            </table>

LoginAction中写:
public ActionForward doAction(ActionMapping mapping,
                                  RequestContext req) {
        String forward = "menu";
        BaseForm frm = (BaseForm)req.getForm();
        System.out.println(frm.get("username"));
        System.out.println(frm.get("password"));
        // ......        
        return mapping.findForward(forward);
}

BaseForm中写:
public class BaseForm extends ActionForm {
    private HashMap data = new HashMap();

    public HashMap getData() {
         return data;
    }

    public void setData(HashMap data) {
        this.data = data;
    }

    public String get(String key) {
        return (String) data.get(key);
    }

    public void set(String key, Object value) {
        data.put(key, value);
    }
}

struts-config.xml中写:
 <form-beans>
    <form-bean       name="baseform"     type="com.web.system.base.BaseForm"/>
  </form-beans>

AJAX——新手快车道(前言):【上一篇】
对"UP是正楷,XP是草书"的反思:【下一篇】
【相关文章】
  • action中对于actionform的传递
  • 基于Context的数据缓存与属性的LazyLoad,一个范型的练习。(24日更新-DataPair能复活来延迟回收)
  • Lazy Singleton的Java实现
  • Struts中不同的Action和ActionForm组合
  • 创建JSP文件和ActionForm Bean
  • ActionForm的生命周期浅探
  • 【随机文章】
  • MapGuide OpenSource 使用中的几个问题的解决
  • 将Java程序作成exe文件的几种方法(转载)
  • 用FreeBSD作NAT服务器
  • "已在多处定义"的错误
  • 文件损坏的恢复
  • 最新常用软件 [与官方同步更新]
  • JAVA起航
  • SQLite简介[转载]
  • IE 和 Firefox 都兼容的文字滚动效果
  • 关于GNU-make v3.80中文版的版权声明
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.