1

こんにちは、

私は次のことを行う必要がある jsp 環境でプログラミングしています
:フィールドとこれを変数に設定し、次に同じことを行いますが、今回は 2 番目の値を追加し、結果を 2 番目の変数に設定し、最後に両方の結果をクエリに渡します。減算は機能しますが、加算の代わりに、2 番目の変数を設定するときに、2 番目の入力フィールドの値を最初の値に追加するだけです。s:property でこれを解決するにはどうすればよいですか? < s:property value="${"(...)first"+"(...)second"}"/> を使用してみましたが、ランタイム式をサポートしていないというエラーが表示されます。コード:

    <s:set name="thequery">
        <s:iterator value="#attr.var" status="status">
            <%--(...)other unrelevant code--%>
            <s:if test="#attr.xinput3[#status.index] != 0">
                <%--the one below works fine-->
                <s:set name="around1">
                        <s:property value="#attr.xinput[#status.index]-#attr.xinput3[#status.index]" />
                </s:set>
                <%--this one just appends the value of xinput3[] to the value of xinput[], instead of adding them-->
                <s:set name="around2">
                        <s:property value="#attr.xinput[#status.index]+#attr.xinput3[#status.index]" />
                </s:set>
                <s:property value="#attr.xvar[#status.index]" />=<s:property
                        value="around1" />!<s:property value="around2" />;</s:if>
            <s:else>
                            <%--unrelevant code--%>
            </s:else>
        </s:iterator>
    </s:set>

結果: たとえば、xinput[] = 12 および xinput3[] = 2 の場合:

10!122;

私はそれが必要な間

10!14;

どうすればこれを修正できますか?

4

2 に答える 2

0

私は自分で答えを見つけました:

<s:if test="#attr.xinput3[#status.index] != 0">
                    <s:set name="around1">${xinput[status.index]-xinput3[status.index]}</s:set>
                    <s:set name="around2">${xinput[status.index]+xinput3[status.index]}</s:set>
                    <s:property value="#attr.xvar[#status.index]" />=<s:property
                        value="around1" />!<s:property value="around2" />;</s:if>

上記のように記述した場合、 < s:set> はランタイム式をサポートしていることがわかります。今はうまくいきます。

于 2013-08-09T14:27:41.153 に答える
0

あなたの値は、数値ではなく文字列として解釈されています。値が整数の場合、加算を行う前に新しい Integer オブジェクトを作成できます。

<s:property value="new java.lang.Integer(#attr.xinput[#status.index]) +
                   new java.lang.Integer(#attr.xinput3[#status.index])" />
于 2013-08-09T12:22:23.590 に答える