如何在Tomcat中访问环境变量?

huangapple 未分类评论44阅读模式
英文:

How am I able to access environment variables in Tomcat?

问题

根据Tomcat官方文档以及我在其他在线资源中看到的内容,部署到Tomcat的Java Servlet代码无法访问环境变量。只能从Java代码中访问在setenv.sh或catalina.sh中明确设置的值。

然而,在测试我的Tomcat设置时,我明显可以从Java代码中访问环境变量。这些变量没有在setenv.sh或catalina.sh中设置。

我正在使用Tomcat版本8.5.35,在他们自己的RUNNING.txt中,明确说明不能从Java代码中访问环境变量。

我能够访问这些变量,是不是一个错误?是否有其他人之前遇到过类似情况?

还有一些可能相关的要点:

  • 我在本地设置了Tomcat。Tomcat安装在我家目录的本地文件夹中。
  • 操作系统:Ubuntu 16.04
  • 使用bin/startup.sh启动Tomcat。
英文:

Based on Tomcat official documentation and from what I've seen elsewhere online, the Java servlet code deployed to Tomcat, cannot access Environment variables. Only the values explicitly setup in setenv.sh or catalina.sh can be accessed from the Java code.

But, when I'm testing out my Tomcat setup, I can clearly access environment variables from the Java code. These variables have not been setup in setenv.sh or catalina.sh

I'm using tomcat version 8.5.35 and in their own RUNNING.txt, it states that environment variables cannot be accessed from the Java code.

Is the fact that I'm able to access them a bug? Has anyone else encountered this before?

Some more points that might be relevant:

  • I have a local setup of tomcat. The tomcat installation resides in a local folder in my home directory
  • OS: Ubuntu 16.04
  • Start tomcat with bin/startup.sh

huangapple
  • 本文由 发表于 2020年4月8日 20:37:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/61100842.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定