我有,我定义的会话变量名称这样一个java Constant.java文件:JSTL动态移除标签
package com.pakageName;
public class Config {
// name of sessions var
public static final String ATT_SESSION_USER = "session_user";
public static final String ATT_SESSION_MESSAGE = "session_message";
...
}
在Servlet的文件,我用下面的定义会话VAR:
session.setAttribute(Constant.ATT_SESSION_MESSAGE, "this is the content of the var I wan't to display on the page");
的Constant.java文件使用包含在我的JSP文件:
<%@ page import="com.pakageName.Config" %>
所以我能够得到sessionSco的内容PE与VAR:
// get the content of the session var
${sessionScope[Constant.ATT_SESSION_MESSAGE]}
// which return the same result as
${sessionScope.session_message}
问题是,我怎么能删除使用删除与恒VAR值标签的会议无功?
我试过以下,但var属性不接受EL表达式...
// throw exception because var attribute doesn't accept el
<c:remove var="${sessionScope[Constant.ATT_SESSION_MESSAGE]}" scope="session" />
<c:remove var="${Constant.ATT_SESSION_MESSAGE}" scope="session" />
// don't remove anything
<c:remove var="Constant.ATT_SESSION_MESSAGE" />
// work but the name is hard coded
<c:remove var="session_message" scope="session" />
任何想法?
不应该只是:' '? –
不,因为这将尝试删除常量变量,而不是名称为Constant.ATT_SESSION_MESSAGE(该变量称为“session_message”)内容的会话变量 –
对不起,但你错了。删除常数?我不知道你在做什么。 https://www.tutorialspoint.com/jsp/jstl_core_remove_tag.htm –