仅对基于servlet的webapp中的某些页面使用HTTPS

Kes*_*hav 7 https tomcat web.xml servlets

我在Tomcat 6服务器上运行了一个基于servlet的webapp.URL方案是HTTPS.整个网站目前正在通过HTTPS提供.但我真正想做的是仅针对某些操作(如购买和登录)设置HTTPS.Tomcat中是否有任何可以帮助我轻松完成此任务的配置?

是否需要对通过HTTPS和HTTP持久化会话进行任何代码更改?

Sea*_*wen 11

实际上,理想情况下,这是在您的Web应用程序的web.xml文件中配置的.您只需指定一些应该是安全的URL,<security-constraint><web-resource-collection>并指定HTTPS要求,<transport-guarantee>其值为CONFIDENTIAL.容器将透明地管理重定向.简单.

<security-constraint>
  <web-resource-collection>
     <web-resource-name>My Secure Stuff</web-resource-name>
     <url-pattern>/some/secure/stuff/*</url-pattern>
     <url-pattern>/other/secure/stuff/*</url-pattern>
     ...
  </web-resource-collection>
  <user-data-constraint>
     <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)