4

我正在尝试在 eclipse 中的 tomcat 上运行一个 servlet。当我在服务器上运行时,servlet 运行并为我提供如下链接:

“http://localhost:8443/AuthServer/Server”

我已经为 SSL 配置了我的 Tomcat 服务器,如下所示:

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
               maxThreads="150" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" keystoreFile="C:\Users\owner\.keystore" keystorePass="sheetalkshirsagar">

当我在服务器上运行 servlet 时,它仍然使用 http。我希望我的 servlet 链接是“https://...”而不是“http://..”。你是怎样做的?

4

3 回答 3

7

如果您想确保在向该 servlet 发送请求时使用 https 协议,则需要更改WEB-INF/web.xmlWeb 应用程序中的文件。在您的情况下添加此配置参数:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>AuthServer</web-resource-name>
        <url-pattern>/Server</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
于 2012-04-10T16:49:10.417 回答
4

TOMCAT_HOME/conf文件夹中,有一个名为web.xml. 在那里,您必须添加一个security-constraint元素。

<security-constraint>
    <web-resource-collection>
        <web-resource-name>secured page</web-resource-name>
        <url-pattern>/...</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

确保它<url-pattern>与您想要保护的路径相匹配。

于 2012-04-10T16:38:22.880 回答
0

如果我正确理解您的问题,那么您正在http从您的 servlet 提供的网页发布 URL。
如果您需要将请求更改为,https您应该redirect将普通http连接器(在端口中808080拥有它的地方)连接到端口的连接器443
如果你用谷歌搜索tomcat redirect http to https,你会发现很多链接,例如将 tomcat 重定向到 https

但是如果您对真正的安全性感兴趣,我建议您不要重定向

于 2012-04-10T16:57:57.477 回答