该功能主要依靠配置tomcat 下面的config/server.xml文件和web项目的web.xml文件来实现的
server.xml配置:
<Connector protocol="org.apache.coyote.http11.Http11Protocol" port="443"
SSLEnabled="true" minProcessors="5" maxProcessors="75" disableUploadTimeout="true"
acceptCount="100" debug="0" scheme="https" secure="true" clientAuth="false"
sslProtocol="TLS" keystoreFile="key" keystorePass="pwd"
/>
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="443"/>
<Context docBase="projectname" path="/" reloadable="true" />
web.xml配置:
<security-constraint>
<web-resource-collection>
<web-resource-name>sslapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
通过以上配置,可以将所有http请求转换为https!