简体   繁体   English

如何在 Tomcat 7.X 中更改 Session 持久性?

[英]How can I change Session Persistence in Tomcat 7.X?

I am using Tomcat 7.0 and I found a reference of how to change session savings into the database.我正在使用 Tomcat 7.0,我找到了如何将 session 储蓄更改为数据库的参考。 But I don't get how to change org.apache.catalina.session.StandardSession.ACTIVITY_CHECK to true但我不知道如何将org.apache.catalina.session.StandardSession.ACTIVITY_CHECK更改为 true

The link that I am referencing is http://www.intelligrape.com/blog/2010/07/21/tomcat-6-session-persistence-through-jdbcstore/我引用的链接是http://www.intelligrape.com/blog/2010/07/21/tomcat-6-session-persistence-through-jdbcstore/

I am using localhost Tomcat 7.X downloaded as zip, MySQL 5.5, STS 3.1(Incuding Eclipse)我正在使用本地主机 Tomcat 7.X 下载为 zip、MySQL 5.5、STS 3.1(包括 Eclipse)

Any figuring out?有办法吗?

This is a system property ( http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html ) so to set these you have to specify the -D option. 这是一个系统属性( http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html ),因此要设置这些属性,您必须指定-D选项。 In your case "-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true". 在你的情况下“-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK = true”。

But where? 但是哪里? Well, System Properties are given to the Java process when it starts. 好吧,系统属性在启动时会被赋予Java进程。 In case of Tomcat you can use a environment variable called $JAVA_OPTS which is given to the Java process on startup. 对于Tomcat,您可以使用名为$ JAVA_OPTS的环境变量,该变量在启动时提供给Java进程。 So 所以

export JAVA_OPTS="$JAVA_OPTS -Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true" export JAVA_OPTS =“$ JAVA_OPTS -Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK = true”

and then run Tomcat. 然后运行Tomcat。 For this to persist make sure that the user running catalina.sh has this environment variable always set. 为了保持这一点,请确保运行catalina.sh的用户始终设置此环境变量。

add below line in catalina.bat just after where you found other JAVA OPTS already being set.在您发现已设置其他 JAVA OPTS 的位置之后,在 catalina.bat 中添加以下行。 set "JAVA_OPTS=%JAVA_OPTS% -Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true"设置“JAVA_OPTS=%JAVA_OPTS%-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

eg例如

rem Register custom URL handlers rem 注册自定义 URL 处理程序

rem Do this here so custom URL handles (specifically 'war:...') can be used in the security policy rem 在此处执行此操作,以便可以在安全策略中使用自定义 URL 句柄(特别是“war:...”)

set "JAVA_OPTS=%JAVA_OPTS% -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"设置“JAVA_OPTS=%JAVA_OPTS% -Djava.protocol.handler.pkgs=org.apache.catalina.webresources”

set "JAVA_OPTS=%JAVA_OPTS% -Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true"设置“JAVA_OPTS=%JAVA_OPTS%-Dorg.apache.catalina.session.StandardSession.ACTIVITY_CHECK=true”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM