[英]How do you start a java servlet over https?
我正在嘗試在 eclipse 中的 tomcat 上運行一個 servlet。當我在服務器上運行時,servlet 運行並為我提供如下鏈接:
“http://localhost:8443/AuthServer/服務器”
我已經為 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://..”。 你是怎樣做的?
如果您想在向該 servlet 發送請求時確保使用 https 協議,則需要更改 web 應用程序中的WEB-INF/web.xml
文件。 在您的情況下添加此配置參數:
<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>
在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>
與您要保護的路徑匹配。
如果我對您的問題的理解正確,您將從您的 servlet 提供的 web 頁面發布 URL 的http
。
如果您需要將請求更改為https
而不是您應該redirect
普通的http
連接器(在您擁有它的端口80
或8080
中)重定向到端口443
的連接器。
如果你谷歌tomcat redirect http to https
你會發現很多鏈接,例如重定向 tomcat 到 https
但如果您對真正的安全性感興趣,我建議您不要重定向
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.