一、CMD运行以下代码:
%JAVA_HOME%\bin\keytool -genkey -alias server -keyalg RSA -keystore e:\server.keystore-validity 3650
-alias是指定一个别名,类似于Map的key
-keyalg是指定算法,默认是DSA
-keystore是生成的文件往哪里放
-validity是证书有效期,3650就是10年
或(C:“ProgramFiles”\Java\jdk1.6.0_43\bin\keytool -genkey -alias server -keyalgRSA -keystore e:\server.keystore -validity3650)(保证有e盘,如果没有改其他盘)
根据提示执行操作
二、设置的是E盘 运行完成会在E盘生成server.keystore
把server.keystore放在tomcat的根目录下
打开D:\apache-tomcat-6.0.372\conf\server.xml
新增
<Connectorport=“443” protocol=“org.apache.coyote.http11.Http11NioProtocol”
minSpareThreads="5"maxSpareThreads=“75” enableLookups="true"disableUploadTimeout=“true”
acceptCount=“100” maxThreads=“200” scheme=“https” secure=“true” SSLEnabled=“true”
clientAuth="false"sslProtocol=“TLS”
keystoreFile=“D:\apache-tomcat-6.0.372\server.keystore” keystorePass=“123456”/>
(注意红色部分)
三、修改项目中的web.xml(实现http协议跳转https协议)
增加
<security-constraint>
<web-resource-collection>
<web-resource-name>HtmlAdaptor</web-resource-name>
<description>An examplesecurity config that only allows users with the
role JBossAdmin to access the HTMLJMX console web application</description>
<url-pattern>/</url-pattern>
<!--<http-method>GET</http-method><http-method>POST</http-method> -->
</web-resource-collection>
<!--<auth-constraint><role-name>JBossAdmin</role-name> </auth-constraint>-->
<user-data-constraint>
<description>Protectionshould be CONFIDENTIAL</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
server.xml配置,这步目的是让非ssl的connector跳转到ssl的connector去,redirectPort改成ssl的connector的端口443,重启后便会生效。
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />