我想在我的一个不安全页面中嵌入一个指向我的应用程序安全页面的链接。 安全 tomcat 端口在 server.xml 文件中配置。在某些部署中,它是 443、8443 等。 所以我需要的是一种从 tomcat 配置中读取安全端口以在链接中使用它的方法。这可能吗?
或者,简单地访问 server.xml 配置(从请求的上下文中)并自己解析它以找出端口号也是可以接受的,但不太理想。
我知道可能有多个连接器和几个安全连接器,所以我将让我的程序逻辑来决定选择哪一个。问题是 - 我如何获得该信息?
谢谢!
最佳答案
我很确定没有用于此的 API。您可能可以通过 web.xml 中的 servlet environ 参数保持它的可配置性。明显的缺点是您现在有 2 个地方配置了 SSL 端口号。
另一种方法是在 web.xml iirc 中配置安全性,例如
<security-constraint>
<web-resource-collection>
<web-resource-name>MyLoginPage</web-resource-name>
<url-pattern>/login</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
您可以只使用登录页面的普通链接,tomcat 应该会自动将 redicts 发送到 ssl 连接器,无论配置到哪个端口。
关于java - Tomcat:如何在 Java 中获取安全端口号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1233871/