Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何通过BeanELResolver正确解析名称_Java_Jsp_Resolver - Fatal编程技术网

Java 如何通过BeanELResolver正确解析名称

Java 如何通过BeanELResolver正确解析名称,java,jsp,resolver,Java,Jsp,Resolver,我们必须使用Java中具有以下属性的非常特定的类: protected SPSExchangedDocumentType spsExchangedDocument; public SPSExchangedDocumentType getSPSExchangedDocument() { return spsExchangedDocument; } 我在jsp页面中使用该类的实例: 它引发了以下异常: javax.el.PropertyNotFoundException:类 'un.une

我们必须使用Java中具有以下属性的非常特定的类:

protected SPSExchangedDocumentType spsExchangedDocument;

public SPSExchangedDocumentType getSPSExchangedDocument() {
  return spsExchangedDocument;
}
我在jsp页面中使用该类的实例:

它引发了以下异常:

javax.el.PropertyNotFoundException:类 'un.unece.uncefact.data.standard.spscertificate._5.SPSCertificateType' 不具有属性“SPSExchangeDocument”。在 getBeanProperty(BeanELResolver.java:579)位于 javax.el.BeanELResolver.getValue(BeanELResolver.java:281)位于 getValue(CompositeELResolver.java:175) 位于com.sun.el.parser.AstValue.getValue(AstValue.java:138) com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:206) 在 org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1001)

我认为问题直接在于这样一个事实,即属性名为spsExchangedDocument,而方法名为getSPSExchangedDocument。我不能更改类的代码,因为它是从XSD自动生成的,我们不能更改,所以我应该更改页面。但是我应该使用什么名称才能让EL正确地解决它:

  • 交换文件
  • 交换文件
  • 交换文件

java和EL中这种命名约定的规则是什么?

假设
BeanELResolver
实现符合:

8.8推断名称的大写。

因此,当我们从 在现有的Java名称中,我们通常将第一个字符转换为下一个字符 案例但是为了支持偶尔使用所有大写名称, 我们检查名称的前两个字符是否都是大写 如果是这样,就别管它了。那么比如说,

  • “FooBah”变成“FooBah”
  • “Z”变成“Z”
  • “URL”变为“URL”
将属性名称解析为
SPSExchangedDocument

import java.beans.*;

public class Bean {
  public Object getSPSExchangedDocument() {
    return null;
  }

  public static void main(String[] args) throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(Bean.class);
    for (PropertyDescriptor prop : info.getPropertyDescriptors()) {
      System.out.println(prop.getName());
    }
  }
}

也就是说,以前在这方面有过错误。

一般来说,getter和setter的命名是属性的名称,第一个字符大写,前面加上get/set。因此,请使用GetSPSExchangeDocument进行尝试。通常这可以由您选择的IDE生成。再一次,我不能更改getter的名称,因为它是由Jaxb工具自动生成的。