我有,我定義的會話變量名稱這樣一個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 –