Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.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 如何将BigDecimal传递给自定义标记库(WebSphere)_Java_Jsp_Websphere_Taglib - Fatal编程技术网

Java 如何将BigDecimal传递给自定义标记库(WebSphere)

Java 如何将BigDecimal传递给自定义标记库(WebSphere),java,jsp,websphere,taglib,Java,Jsp,Websphere,Taglib,我有一个自定义taglib,我尝试将其设置为BigDecimal,但没有保持比例。似乎BigDecimal被转换为double,然后又回到BigDecimal。这是WebSphere中的错误吗?还是我遗漏了什么 我的控制器(我正在使用Spring): @控制器 @请求映射(“/BigDecimalTest”) 公共类BigDecimalTestController{ @请求映射 公共字符串显示(最终地图模型){ 型号.put(bigDecimal),新的bigDecimal(126.58);;

我有一个自定义taglib,我尝试将其设置为BigDecimal,但没有保持比例。似乎BigDecimal被转换为double,然后又回到BigDecimal。这是WebSphere中的错误吗?还是我遗漏了什么

我的控制器(我正在使用Spring):

@控制器
@请求映射(“/BigDecimalTest”)
公共类BigDecimalTestController{
@请求映射
公共字符串显示(最终地图模型){
型号.put(bigDecimal),新的bigDecimal(126.58);;
返回“bigDecimalTest”;
}
}
我的JSP:

<%@taglib uri="/custom-taglibs/bigDecimal.tld" prefix="bd"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <title>BigDecimal Test</title>
</head>
<body>
<bd:display value="${bigDecimal}"/>
</body>
</html>

大十进制检验
我的标记库描述符:

<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
  <description>BigDecimal test</description>
  <tlib-version>1.0</tlib-version>
  <short-name>bd</short-name>
  <tag>
    <description>Display informations about a BigDecimal</description>
    <name>display</name>
    <tag-class>BigDecimalDisplay</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>value</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
      <type>java.math.BigDecimal</type>
    </attribute>
  </tag>
</taglib>

大十进制检验
1
屋宇署
显示关于大十进制的信息
陈列
大小数显示
空的
?

先生。 如果你知道你想要多少个小数,也许你可以做一些类似家长的事情。 链接: 我希望这对你有帮助。
吉利安先生

实际上,我不知道小数的数目。刻度是以大十进制设置的,我想我会保留它。不管怎样,谢谢你。那是一种混乱的方式。当然,以您想要的方式转换值是没有问题的,问题是为什么会发生这种转换以及如何防止它。您正在与症状作斗争,而不是解决实际问题;)我无法在我的应用程序中重现错误。我创建了与您相同的标记,具有相同的标记库定义。标签按预期显示“值126.58”和“刻度2”。我的应用程序使用Jetty运行,不使用Spring。@Obourg很有趣。所以这可能是一个WebSphere或Spring错误。
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
    version="2.0">
  <description>BigDecimal test</description>
  <tlib-version>1.0</tlib-version>
  <short-name>bd</short-name>
  <tag>
    <description>Display informations about a BigDecimal</description>
    <name>display</name>
    <tag-class>BigDecimalDisplay</tag-class>
    <body-content>empty</body-content>
    <attribute>
      <name>value</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
      <type>java.math.BigDecimal</type>
    </attribute>
  </tag>
</taglib>
public class BigDecimalDisplay extends TagSupport {

    private static final long serialVersionUID = 2049900195699675393L;

    private BigDecimal value;

    public void setValue(final BigDecimal value) {
        this.value = value;
    }

    @Override
    public int doStartTag() throws JspException {
        final JspWriter out = pageContext.getOut();
        try {
            out.print("<div>");
            out.print("<div>Value: ");
            out.print(value.toPlainString());
            out.print("</div>");
            out.print("<div>Scale: ");
            out.print(value.scale());
            out.print("</div>");
            out.print("</div>");
        } catch (final IOException e) {
            throw new JspException(e);
        }
        return SKIP_BODY;
    }

}