Java web加密之将应用从http换成https的方法

 转载:https://www.cnblogs.com/yangyang2018/p/8421453.html

感谢文章http://blog.csdn.net/zhangzuomian/article/details/50324395 

大致分2步:1、获取证书。2、修改tomcat的config/server.xml和项目中web.xml配置

打开config/server.xml,取消下面8443端口代码的注释,并修改如下:

1
2
3
<Connector port="8443"protocol="HTTP/1.1" SSLEnabled="true"     maxThreads="150" scheme="https" secure="true"    
  clientAuth="false"keystoreFile="D:/AppServer/Tomcat/apache-tomcat-6.0.32/conf/tomcat.keystore"    
  keystorePass="1234567" sslProtocol="TLS" />  

  注:
keystoreFile:证书文件的位置,keystorePass 是keystore的密码(你在生成证书的时候,会有的keystore密码和tomcat主密码)

项目中web.xml添加如下:、

1
2
3
4
5
6
7
8
9
10
<security-constraint>  
       <web-resource-collection>  
              <web-resource-name>SSL</web-resource-name>  
              <url-pattern>/*</url-pattern>  
       </web-resource-collection
   
       <user-data-constraint>  
              <transport-guarantee>CONFIDENTIAL</transport-guarantee>  
       </user-data-constraint>  
</security-constraint

  转载自http://blog.csdn.net/rainyspring4540/article/details/68925073