本地环境Tomcat5.5+JDK1.6
首先第一步,生成一个.keystore文件。。
我用的JDK自带的keytool工具,在Java\jre1.6.0_03\bin目录下面如图所示
在命令行切换到目录下面
![]() | ![]() | ![]() |
![]() | keytool -genkey -alias tomcat -keyalg RSA |
执行该命令就会在你的用户根目录下面生成一个.keystore文件
然后把tomcat下面的conf下面的server.xml
<Connector port="8443"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
keystoreFile="/Users/xwtec/.keystore"
acceptCount="100" debug="0" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
中的这一段注释去掉
并替换为这一段
<Connector port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" disableUploadTimeout="true"
acceptCount="100" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="C:/Users/xwtec/.keystore"
keystorePass="123456"/> <!--生成keystore文件时输入的密码-->
记住。。tomcat版本不一样。。这一段的写法可能不一样 这是tomcat5的写法
然后你启动 tomcat 发会现
上面的图中有个锁
恭喜你成功了
可以点开查看你的证书
是不是很简单
在项目工程的web.xml中
<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>*.js</url-pattern>
<http-method>GET</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
加上这些配置
你就会发现你的工程中的js不能访问了。。
参考文档http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html