【发布时间】:2014-02-28 18:20:17
【问题描述】:
我们在旧版 Web 应用程序中使用 Struts Tiles 1.x。在a.jsp,我们这样做:
<tiles:put name="bean" beanName="change"></tiles:put>
后来,b.jsp 引用了a.jsp。在b.jsp,我们目前有一个scriptlet,我们在其中做:
<% DomainObject domObject = (DomainObject) TilesHelper.getAttribute("bean", pageContext); %>
这是getAttribute(String,PageContext) 的样子:
public class TilesHelper {
public static Object getAttribute(String name, PageContext pageContext) throws JspException {
ComponentContext compContext = (ComponentContext) pageContext.getAttribute(
ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
if (compContext == null) {
throw new JspException("Error - tag.getAttribute : component context is not defined. Check tag syntax");
}
return compContext.getAttribute(name);
}
这可行,但我不喜欢 scriptlet。小脚本很丑陋。我不想要这个 JSP 中的任何小脚本。我想使用标签来访问在请求范围中传递的对象。我试过了
<bean:define id="domObject" name="bean" scope="request"/>
这失败,错误找不到 bean bean in scope request.
我如何访问在<tiles:put> 调用中传递的对象,其标记为<bean:define> 或<jsp:useBean>?
谢谢
【问题讨论】: