2

和有什么区别

<tiles:useAttribute ...>

<tiles:insertAttribute ...>

你能举一些例子吗?

4

2 回答 2

3

请参阅http://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/insertAttribute.htmlhttp://tiles.apache.org/2.2/framework/tiles-jsp/tlddoc/tiles/useAttribute .html

useAttribute声明一个包含该属性的变量。insertAttribute在响应中插入属性。这与两者之间的区别基本相同

String id = attributeValue("theAttribute");

out.println(attributeValue("theAttribute"));
于 2012-06-20T21:50:57.670 回答
3

谢谢@JB 尼泽特!

实际上我需要在 jsp 页面中使用这个 tile 属性。我发现了你所解释的差异和几乎相同的东西。但是,我想将我的示例分享给那些在 jsp 页面上尝试的人

myLayout.jsp的代码片段

<tiles:useAttribute name="my_title"/>
<c:if test="${not empty my_title}">
    <tiles:insertAttribute name="my_title"/>
</c:if>

useAttribute将在某种意义上将“my_title”转换为现在可以作为普通 jsp 变量进行操作的变量。这个新变量将携带瓷砖定义提供的值。因此,可以检查变量是否为空或空白,如果不为空,则使用insertAttribute将值输出到浏览器(响应)

这是示例磁贴定义:

<definition name="test" template="myLayout.jsp">    
    <put-attribute name="my_title" value="Web Blog" />
</definition>

请享用!

于 2012-06-21T18:43:09.493 回答