MyEclipse開發Struts中的form的property的第一個字母只能上小寫。。

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章