MyEclipse开发Struts中的form的property的第一个字母只能上小写。。

本文探讨了在MyEclipse中使用Struts框架开发时,表单元素的属性名称必须遵循JavaBean规范,即属性名首字母需为小写的问题。详细解释了这一规范的原因,并给出了正确的实现方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MyEclipse开发Struts中的formproperty的第一个字母只能上小写。。
BY: Border
 
<html:form action="/userLogin.do">                     

 PassWord : <html:password property="PassWord"/>

 UserName : <html:text property="userName"/>

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


中的property="PassWord"中的第一个字母必须是小写。如果是大写就报错。不过是小写的话就通过。。。

 
這不是程式的問題,也和eclipse無關,而是JavaBean的規格本來就是這樣規定

精華區中[JSTL1.1中的JavaBean取值問題] , 在JavaBeans spec 8.8 有說明,
節錄於下:
When we use design patterns to infer a property name, we need to decide whatrulesto follow for capitalizing the inferred name. If we extract the name from the middle of a normal mixedCase style Java name then the name will, by default, begin with a capital letter.

Java programmers are accustomed to having normal identifiers start with
lower case letters.Vigorous reviewer input has convinced us that we should follow this sameconventional rule
for property names.

Thus when we extract a property name from the middle of an existing Javaname, we normally convert the first character to lower case.

However to support the occasionaluse of all upper-case names, we check if the first two characters of the name are both upper case and if so leave it alone.
So for example,

"FooBah" becomes "fooBah"
"Z" becomes "z"
"URL" becomes "URL"
=============================================
也就是說,因為您的METHOD是 getM_ACCOUNT, 第二個字被判定是小寫(_),所以properties會被認為轉為m_ACCOUNT, 又, ID兩個都是大寫, 所以不必改為 iD. 這種判定也會發生在數字,中文等字元上. 所以如果是getC1ABC,則JavaBean properties會被認為是c1ABC 

struts-html 標籤使用 org.apache.struts.taglib.html.BEAN 這個JavaBean的 getPassWord() 來取得PassWord的值,所以 property 要給定 passWord 才能取到值。

讨论http://www.javaworld.com.tw/jute/post/view?bid=10&id=147373&tpg=1&ppg=1&sty=1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值