jsp:setproperty property ="*"不能设置所有属性 [英] jsp:setproperty property=“*” not set all properties

查看:185
本文介绍了jsp:setproperty property ="*"不能设置所有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含以下内容的jsp页面

i have jsp page which contains

<jsp:useBean id="RcvMsgTransferTanseekBean" class= "com.test.RcvMsgTransferTanseekBean" />  
<jsp:setProperty name="RcvMsgTransferTanseekBean" property="*" />

和其中包含的豆子

private String nId = "";
public void setNId (String value){
    this.nId = value;  
}

public String getNId(){
    return this.nId;
}

我向该jsp页面发送请求

i send request to that jsp page

test.jsp?letId=479438&dstId=522375&nId=138393&subject=66666666666&letForInfo=1&shNotMan=true

我的问题是只有nId参数仍然为空.

my problem is that the nId parameter only is still empty.

当我在jsp中添加新行时

when i added new line in the jsp

<jsp:setProperty name="RcvMsgTransferTanseekBean" property="nId" />

它工作正常,为什么'property ="*"'不能像预期的那样工作?

it works fine, why the 'property="*"' didn't work as the supposed to be ?

推荐答案

问题出在属性名称上.
CamelCase的大写字母和大写字母不起作用,就像您期望的单个前导字母一样. 为了设置属性的值,使用了setter方法.
nId的设置者是setNId.

The issue is in the name of the property.
The Capitalization and Decapitalization of the CamelCase don't work as you expect for single leading letter. For Setting the value of the property the setter method are used.
And the setter for nId is setNId.

Java Bean Spacification 说:

8.8推断名称的大写.

8.8 Capitalization of inferred names.

当我们使用设计模式来推断属性或事件名称时,我们需要 决定要遵循的规则将大写的名称大写.如果 我们从普通的MixedCase样式Java的中间提取名称 名称,然后默认情况下,名称将以大写字母开头.爪哇 程序员习惯于以普通标识符开头 小写字母.审稿人的大力投入使我们深信 对于财产和事件应遵循相同的常规规则 名称.

When we use design patterns to infer a property or event name, we need to decide what rules to 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 same conventional rule for property and event names.

因此,当我们从中间位置提取属性或事件名称时 现有的Java名称,我们通常将第一个字符转换为小写 案子.但是,为了支持偶尔使用所有大写名称, 我们检查名称的前两个字符是否都大写 如果可以的话,请不要管它.例如,

Thus when we extract a property or event name from the middle of an existing Java name, we normally convert the first character to lower case. However to support the occasional use 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"变成"fooBah""Z"变成"z""URL"变成"URL"

"FooBah" becomes "fooBah" "Z" becomes "z" "URL" becomes "URL"

我们提供了Introspector.decapitalize方法来实现 转换规则.

We provide a method Introspector.decapitalize which implements this conversion rule.

公共静态字符串大写(字符串名称)

public static String decapitalize(String name)

使用方法将字符串转换为普通的Java变量 名称大写.这通常意味着先转换 从大写到小写的字符,但在(不寻常的)特殊字符中 如果有多个字符,并且第一个字符和第一个字符 第二个字符是大写,我们不理会它.

Utility method to take a string and convert it to normal Java variable name capitalization. This normally means converting the first character from upper case to lower case, but in the (unusual) special case when there is more than one character and both the first and second characters are upper case, we leave it alone.

因此,"FooBah"变为"fooBah","X"变为"x",但是"URL"保持为 "URL".

Thus "FooBah" becomes "fooBah" and "X" becomes "x", but "URL" stays as "URL".

因此,为了找到参数和设置器之间的匹配项:

  • 二传手获得无资本化.因此,从setNId得出NId.
  • 如果您已提交参数NId,则该值将放入javaBean中,
  • 但是如果您有nId,则找不到匹配的设置器.
  • The setter get decapitalized. So from setNId, we get NId.
  • If you have submitted a parameter NId, the value goes in the javaBean,
  • But if you have nId, there is no matching setter found.

解决方案:避免此类情况:

在属性名称的开头使用多个小写字母.

Use more than one small letter at the begin of property names.

在这种情况下,可以使用numId代替nId.

In this particular case, instead of nId you can use numId.

或将设置器/获取器名称更改为setnId()getnId()

OR Change the setter/getter names to setnId() and getnId()

通过使用具有此类属性和getter/setter名称的Bean发生意外行为

  • <jsp:setProperty name="RcvMsgTransferTanseekBean" property="*" />
    只是跳过属性nId.没错也不例外.
  • <jsp:setProperty name="RcvMsgTransferTanseekBean" property="nId"/>
    抛出org.apache.jasper.JasperException:PWC6054:在类型为com.test.RcvMsgTransferTanseekBean的bean中找不到关于属性"nId"的任何信息
  • ${RcvMsgTransferTanseekBean.nId}
    抛出org.apache.jasper.JasperException:javax.el.PropertyNotFoundException:类'com.test.RcvMsgTransferTanseekBean'没有属性'nId'.
  • <jsp:setProperty name="RcvMsgTransferTanseekBean" property="*" />
    just skips the property nId. No Error. No Exception.
  • <jsp:setProperty name="RcvMsgTransferTanseekBean" property="nId"/>
    throws org.apache.jasper.JasperException: PWC6054: Cannot find any information on property 'nId' in a bean of type 'com.test.RcvMsgTransferTanseekBean'
  • ${RcvMsgTransferTanseekBean.nId}
    throws org.apache.jasper.JasperException: javax.el.PropertyNotFoundException: The class 'com.test.RcvMsgTransferTanseekBean' does not have the property 'nId'.

这篇关于jsp:setproperty property ="*"不能设置所有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆