< – Define a SSL Coyote HTTP/1.1 Connector on port 8443 -->
< !–
< Connector
port=“8443” minProcessors=“5” maxProcessors=“75”
enableLookups=“true” disableUploadTimeout=“true”
acceptCount=“100” debug=“0” scheme=“https” secure=“true”;
clientAuth=“false” sslProtocol=“TLS”/>
–>
Connector元素本身,其默认形式是被注释掉的(commented out),所以需要把它周围的注释标志删除掉。然后,可以根据需要客户化(自己设置)特定的属性。一般需要增加一下keystoreFile和keystorePass两个属性,指定你存放证书的路径(如:keystoreFile=“C:/.keystore”)和刚才设置的密码(如:keystorePass=“123456”)。关于其它各种选项的详细信息,可查阅Server Configuration Reference。
在完成这些配置更改后,必须象重新启动Tomcat,然后你就可以通过SSL访问Tomcat支持的任何web应用程序。只不过指令需要像下面这样:https://localhost:8443
4.客户端代码实现
在Java中要访问Https链接时,会用到一个关键类HttpsURLConnection;参见如下实现代码:
// 创建URL对象
URL myURL = new URL(“https://www.sun.com”);
// 创建HttpsURLConnection对象,并设置其SSLSocketFactory对象
HttpsURLConnection httpsConn = (HttpsURLConnection) myURL.openConnection();
// 取得该连接的输入流,以读取响应内容
InputStreamReader insr = new InputStreamReader(httpsConn.getInputStream());
// 读取服务器的响应内容并显示
int respInt = insr.read();
while (respInt != -1) {
System.out.print((char) respInt);
respInt = insr.read();
}
</