简体   繁体   中英

JSP - Expression Language

I'm preparing for OCEWCD. Below code is appearing in a jsp page

<jsp:useBean id="acct1" class="aaa.bbb.Account"/>

<jsp:useBean id="acct2" class="aaa.bbb.Account " />

And

<jsp:setProperty name="acct2" property="address" value="${acct1.address}" />

This code is trying to copy ”address” attribute of “acct1” object to “acct2” object's “address” attribute.

The explanation saying, the el expression (value="${acct1.address}") brings a reference to the address attribute of acct1 object.

But my understanding is, it will bring the string representation of the address attribute of acct1 object ( like- acct1.getAddress().toString() ).

Because if the following code appearing in a jsp page,

<%
Request.setAttribute(“A”, new A());
%>
${A}

the output might be something like

org.apache.jsp.newjsp_jsp$1A@1bcdccc3.

Explain me. Thanks

The conversion to String takes place only when the object is printed in the output:

<% Request.setAttribute(“A”, new A()); %>
${A} <%-- A.toString() is called here --%>

In <jsp:setProperty name="acct2" property="address" value="${acct1.address}" /> nothing is printed to the output, so no string conversion takes places. In effect, this is the same as acct2.setAddress(acct1.getAddress())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM