tomcat修改jsessionid在cookie中的名稱


1、tomcat5修改方法

在啟動項中增加org.apache.catalina.SESSION_COOKIE_NAME參數

linux
JAVA_OPTS=’-Dorg.apache.catalina.SESSION_COOKIE_NAME=yousessionname

win
set JAVA_OPTS=”-Dorg.apache.catalina.SESSION_COOKIE_NAME=yousessionname

2、tomcat6和tomcat7修改方法相同

在Context容器標簽上增加sessionCookieName參數

<Context path=”/” docBase=”webapp” reloadable=”false” sessionCookieName=”yoursessionname”></Context>

3、為啥這樣就好用呢?

tomcat5時增加參數對所有Context生效,影響甚大,所以到以后的版本就僅針對Context設置了

tomcat5源碼如下
public final class Globals
/**
* The name of the cookie used to pass the session identifier back
* and forth with the client.
*/
public static final String SESSION_COOKIE_NAME =
System.getProperty(“org.apache.catalina.SESSION_COOKIE_NAME”,
“JSESSIONID”);

tomcat6和tomcat7的源碼差不多,如下
public class StandardContext
….省略若干
/**
* The name to use for session cookies. <code>null</code> indicates that
* the name is controlled by the application.
*/
private String sessionCookieName;
/**
* Gets the name to use for session cookies.
*
* @return  The value of the default session cookie name or null if not
*          specified
*/
public String getSessionCookieName() {
return sessionCookieName;
}

/**
* Sets the name to use for session cookies. Overrides any setting that
* may be specified by the application.
*
* @param sessionCookieName   The name to use
*/
public void setSessionCookieName(String sessionCookieName) {
String oldSessionCookieName = this.sessionCookieName;
this.sessionCookieName = sessionCookieName;
support.firePropertyChange(“sessionCookieName”,
oldSessionCookieName, sessionCookieName);
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM