1.tomcat-https配置
keystoreFile 配置的是https證書文件路徑
keystorePass 配置的是https證書密碼
<Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="443" />
<Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/webroot/keystore/XXXX.pfx"
keystorePass="XXXXXX" />
2.tomcat-path配置、即一個tomcat配置多個項目
<Host name="www.xxxx.com"
appBase="webapps"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false">
<Context path="/"
docBase="/home/webroot/project-name"
crossContext="true"
reloadable="true" />
</Host>
3.配置tomcat “http://” 自動跳轉成爲 “https://”
打開/apache-tomcat-6.0.29/conf/web.xml,在該文件</welcome-file-list>後面加上這樣一段:
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
4.瀏覽器訪問http網站,自動跳轉https
tomcat設置,方法有很多,例如:APache、Nginx、IIS都能做到。
這位博主講的很詳細:點擊查看
這裏採用修改tomcat的conf文件夾下的web.xml文件來實現效果
添加以下代碼:
<web-app>
.
.
.
<security-constraint>
<web-resource-collection >
<web-resource-name >SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
.
.
.
</web-app>
5.獲取項目上傳文件絕對路徑【java】
String projectUrl = request.getServletContext().getRealPath("/");
控制檯打印出來的結果爲【注意是編譯後的target文件夾下的路徑】:
D:\JAVA\IDEA-Workspace\shop-member\target\shop-member\