2 java web-container jakarta-ee
如何在 Sun 应用服务器/Web 服务器中将 http 重定向到 https?
transport-guarantee如果您将元素设置为CONFIDENTIAL或INTEGRAL中, servlet 容器应自动将用户重定向到 HTTPS 侦听器web.xml,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
元素url-pattern内容应与您希望保护的路径匹配。因此,例如,如果您想保护 下的所有内容/admin,请指定/admin/*为您的url-pattern. 这应该表现出以下行为:
http://www.example.org/admin/login
Run Code Online (Sandbox Code Playgroud)
将重定向到
https://www.example.org/admin/login
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请查看 Servlet 2.5 规范 ( JSR 154 )。