Struts Struts1例子Struts注意事项

[b]1 表单属性设置问题[/b]
1.1
<input name="parentName" id="parentName" class="s_input" value="123" readonly="readonly"/>
这种StrutsForm 可以获取

<input name="parentName" id="parentName" class="s_input" value="123" disabled="disabled">
这种获取不到

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[b]2 Struts标签[/b]
0 Struts的跳转时forward跳转
1 Struts的form可以给页面表单元素property为form属性的自动设置上值
2 Struts的form可以给页面非表单元素property为form属性的自动设置上值
但是必须指定form-bean的name;例如
<logic:equal name = "loginForm" property="tag" value="user">用户</logic:equal>
name = "loginForm"制定的是配置文件中的formBean

<body>
<html:form styleId="loginForm" action="/login" method="post">
<html:checkbox property="boxoyp" value="0"></html:checkbox>
username: <html:text property="username"/><html:errors property="username"/><br/>
password: <html:text property="password"/><html:errors property="psw"/><br/>
<html:submit /><html:reset/>
</html:form>
</body>
<logic:equal name = "loginForm" property="tag" value="user">用户</logic:equal>
<logic:equal name = "loginForm" property="tag" value="admin">管理员</logic:equal>


[b]3 Struts标签[/b]
<logic:equal  name = "loginForm" property="tag" value="user">用户</logic:equal>

name属性:
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.
property属性,是request.getAttribute中得到的Bean的属性的值

当程序遇到<html:form>标签会去执行相应的程序,会把formBean放在pageContext中,
然后再<html:form>中的其他标签,例如<html:text>就会去执行相应的程序,其中有
pageContext.findAttribute(name);该方法的解释是 Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.

// Store this tag itself as a page attribute
pageContext.setAttribute(Constants.FORM_KEY, this,
PageContext.REQUEST_SCOPE);

所以 在action的配置文件中formBean命名为 testForm,如果在action中在request中放了一个request.setAttribute("testForm",new testDTO());form中标签text标签找的时候 (Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null. ) 则会找到request中的这个testForm
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2010-5-12
页面上form里的元素,style.display = "none"的也可以提交到action
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值