gpt4 book ai didi

java - 理解 semantics

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:39:39 25 4
gpt4 key购买 nike

我正在阅读 Charles Lyon 的 OCWCD <jsp:attribute>我无法理解这部分。如果有人能帮助我,我将不胜感激。

这里是(摘自本书):

方法 1:

<jsp:useBean>  
<jsp:attribute name="id">bean_name<jsp:attribute>
<jsp:useBean>

方法 2:

<jsp:useBean id="bean_name"/> 

"The semantics of both approaches are the same, in that if an attribute is expecting the result of a request time expression, then the container will evaluate the contents of the <jsp:attribute> action; otherwise if the body content of <jsp:attribute> is a request time expression, a translation exception will be thrown."

知道他想说什么吗?

最佳答案

JavaServer Pages 2.3 规范声明

• For standard or custom action attributes that accept a request-time expression value, the Container must evaluate the body of the action and use the result of this evaluation as the value of the attribute. The body of the attribute action can be any JSP content in this case. If the type of the attribute is not String, the standard type conversion rules are applied, as per Section JSP.1.14.2.1, “Conversions from String values”.

例子:

<jsp:element>的属性接受请求时表达式值,因此以下示例将评估操作的主体。

<jsp:element name="xmlElement">
<jsp:attribute name="xmlElementAttr">${param.test}</jsp:attribute>
</jsp:element>
<jsp:element name="xmlElement">
<jsp:attribute name="xmlElementAttr"><%=request.getParameter("test")%></jsp:attribute>
</jsp:element>


• For standard or custom action attributes that do not accept a request-time expression value, the Container must use the body of the action as the value of the attribute. A translation error must result if the body of the action contains anything but template text.

例子:

property <jsp:getProperty> 的属性不接受请求时表达式值。所以下面的例子会得到翻译错误

<jsp:getProperty name="bean1">
<jsp:attribute name="property">${param.test}</jsp:attribute>
</jsp:getProperty>

关于java - 理解 <jsp :attribute> semantics,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com