struts1.2 Form 中的Proterties属性

用SOA架构OA的时候,jsp页面是由专门的模板生成,通过生成的jsp页面要完成增删改查等操作。
表单的信息都有专门的表保存(内容类别表),保存着数据库中所有的表单信息,如表单的名称,表单所拥有的字段,字段别名,字段类型,字段长度等信息。
用模板生成表单也应的页面,当然在内容类别表中查询表单中对应的字段,用java代码拼JSP文件,但是为了新增时Action抓取数据方便,这里我们用到了Properties。所有表单的值都用这个Properties属性来抓取,看实例吧!
Form表单
public class PersonForm extends ActionForm {

public PersonForm()
{
System.out.println("初始化Action");
display = new Properties();
display.setProperty("name", "gu_zdong");
}

private [color=red]Properties [/color]display;


public Properties getDisplay()
{
return display;
}

public void setDisplay(Properties display)
{
System.out.println("display is "+display.toString());
this.display = display;
}

}


jsp页面
<html>
<head>
<base href="<%=basePath%>">

<title>index</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
td
{
font-size:13px;
}
</style>
</head>

<body>
<html:form action="/person.do" method="post">
<table align="center">
<tr>
<td>姓名</td>
<td>
<html:text property="display(name)"></html:text>
</td>
</tr>
<tr>
<td>电话</td>
<td>
<html:text property="display(phone)"></html:text>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<html:submit value="提交"></html:submit>
</td>
</tr>
</table>
</html:form>
</body>

</html>


Action
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
PersonForm person = (PersonForm)form;
Properties p = person.getDisplay();
System.out.println(p.toString());
return null;
}


运行的jsp界面
[table]
| 姓名:gu_zhong
|
| 电话:|
[/table]

姓名展现是因为在form的构造方法中,初始化了个值。

如果在电话上填写 1111111111
运行效果:
[color=darkblue]{phone=1111111111, name=gu_zdong}[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值