是否可以将会话中的对象传递给 JSP 标记属性?
即我有一个类存储有关菜单节点的信息。我将其对象存储在"app.menu"
密钥下的会话中。
我创建了菜单标签处理程序:
public class MenuTagHandler extends TagSupport {
private static final long serialVersionUID = 7116890687703774365L;
private Menu menu;
private String id;
private String cssClass;
private Logger logger = Logger.getLogger(this.getClass());
@Override
public int doStartTag() throws JspException {
logger.info("tagSupport doStartTag method entered");
return SKIP_BODY;
}
public Menu getMenu() {
return menu;
}
public void setMenu(Menu menu) {
this.menu = menu;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCssClass() {
return cssClass;
}
public void setCssClass(String cssClass) {
this.cssClass = cssClass;
}
}
顶级域名文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>menu</short-name>
<description>Vertical menu tag</description>
<tag>
<name>cloudUMLMenu</name>
<tag-class>clouduml.menu.MenuTagHandler</tag-class>
<description>Menu tag handler</description>
<attribute>
<name>menu</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>clouduml.menu.Menu</type>
</attribute>
<attribute>
<name>id</name>
<required>false</required>
</attribute>
<attribute>
<name>cssClass</name>
<required>false</required>
</attribute>
</tag>
</taglib>
JSP 文件中的调用:
<menu:cloudUMLMenu menu="#session['app.menu']"/>
不幸的是我总是得到例外:
org.apache.jasper.JasperException: Unable to convert string "#session['clouduml.menu']" to class clouduml.menu.Menu
Ofc 我可以将密钥传递"app.menu"
给menu
属性并MenuTagHandler
从会话中读取菜单数据,但我想知道是否可以使用 OGNL。