【发布时间】:2009-02-10 08:24:14
【问题描述】:
如何在 Sun Application Server / Web Server 中将 http 重定向到 https?
【问题讨论】:
标签: java jakarta-ee web-container
如何在 Sun Application Server / Web Server 中将 http 重定向到 https?
【问题讨论】:
标签: java jakarta-ee web-container
如果您在web.xml 中将transport-guarantee 元素设置为CONFIDENTIAL 或INTEGRAL,servlet 容器应自动将用户重定向到 HTTPS 侦听器,如下所示:
<security-constraint>
<web-resource-collection>
<web-resource-name>All</web-resource-name>
<url-pattern>*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
url-pattern 元素内容应与您希望保护的路径匹配。因此,例如,如果您想保护/admin 下的所有内容,请将/admin/* 指定为您的url-pattern。这应该表现出以下行为:
http://www.example.org/admin/login
将重定向到
https://www.example.org/admin/login
有关更多信息,请查看 Servlet 2.5 规范 (JSR 154)。
【讨论】:
一种可能的方法是使用 mod_rewrite
我确定还有其他人。
【讨论】: