LuckY07
LuckY07

Reputation: 421

Tomcat 7 - where do I set 'system properties'?

My webapp is having an issue since upgrading to Tomcat 7. My session will go null after I login and try to do anything (submitting a request). I've read that setting the following may help:

org.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false

Does anyone know where to set this? Should this be set in web.xml, context.xml or somewhere else?

The other thing I want to check is the following:

org.apache.catalina.STRICT_SERVLET_COMPLIANCE

Upvotes: 35

Views: 102111

Answers (6)

Ben Hutchison
Ben Hutchison

Reputation: 5103

When running Tomcat on Windows using the Apache Commons Daemon Service Runner (Tomcat.exe), setenv.bat is ignored (see RUNNING.txt section 3.4).

Instead, you can set system properties using the Tomcat Properties program.

GUI

  1. Run Tomcatw.exe
  2. Go to the Java tab
  3. Insert your system property key-value pair into the Java Options text box using the format -D{key}={value}
  4. Click Apply
  5. Restart the Tomcat service
Tomcat Properties

Registry

If you don't want to use the GUI, this text is persisted in the Options value of the registry key HKLM\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\Tomcat\Parameters\Java (on x64 Windows).

Upvotes: 0

Sreevidya Aravind
Sreevidya Aravind

Reputation: 433

You can set system properties in Tomcat by creating a setenv.sh file in /bin directory. I did the following to set the system properties.

export JAVA_OPTS="-Dmyprojectvar.subname=value -Danothervariable=value -Danother.variable=value"

Remember:

There is no space between the export JAVA_OPTS and =. Also: the symbol & is different, use ..

Now, run your catalina.sh to start tomcat.

Upvotes: 19

Brent Sandstrom
Brent Sandstrom

Reputation: 839

If you are trying to set variables for a server running in eclipse:

  1. Select Run > Run Configurations
  2. Make sure your server is selected
  3. Select Environment Tab
  4. Click 'New' to add a new variable

Upvotes: 1

user2335780
user2335780

Reputation: 529

You can set any of the system properties in

apache-tomcat-7.0.33\conf\catalina.properties

file. Adding your entry in this file should resolve your problem.

E.g.

environment=local

Upvotes: 45

LuckY07
LuckY07

Reputation: 421

THE SOLUTION:

sessionCookiePathUsesTrailingSlash="false"

We actually figured out how to solve this. It was a Tomcat 7 setting we needed to set. We placed it in server.xml, under the tag as follows:

<Context path="/test" reloadable="true" docBase="c:\webapp\test" 
workDir="c:\webapp\test" sessionCookiePathUsesTrailingSlash="false"/>

When we were debugging the problem and looking at the cookies path we noticed it was putting a \ backslash after the webapp name, so for our test webapp it was setting the path to /test/ instead of /test. This caused a bunch of problems.

Has anyone else had to deal with this setting in Tomcat 7? Or have a similar problem?

Upvotes: 3

igr
igr

Reputation: 10604

You can set these system properties in command line that starts Tomcat. For example, you can have file setenv.bat (on setenv.sh if you are on linux) in Tomcats bin folder with following content:

set "CATALINA_OPTS=%CATALINA_OPTS% -Dfile.encoding=UTF8 -Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true -Duser.timezone=GMT -Xmx1024m -XX:MaxPermSize=256m"

This file is preferred way of setting properties for Tomcat.

Now, FWD_SLASH_IS_SEPARATOR is by default set to false. If you set STRICT_SERVLET_COMPLIANCE to true, the value of FWD_SLASH_IS_SEPARATOR will be also set to true (and values of some other properties). However, you can set it explicitly to false, e.g. using the following in your setenv file is fine:

-Dorg.apache.catalina.STRICT_SERVLET_COMPLIANCE=true
-Dorg.apache.tomcat.util.http.ServerCookie.FWD_SLASH_IS_SEPARATOR=false

This is also what I suggest when someone sets STRICT_SERVLET_COMPLIANCE to true, to always disable the FWD_SLASH_IS_SEPARATOR. Otherwise, the cookie Path value will be sent quoted (e.g. "\") and all browsers as of today, except Opera, do not recognize this and would e.g. fail to track the session.

Upvotes: 5

Related Questions