Using the HTTPS security protocol method

Source: Internet
Author: User
1 Using the Java Interceptor method to implement the protocol jump (currently can not, use the following JS method, this is provided by another method)
This class implements the filter interface, which requires the configuration of interceptors in Web.xml


public void Dofilter (ServletRequest request, servletresponse response,
Filterchain chain)
Throws IOException, Servletexception {
HttpServletRequest httpservletrequest = (httpservletrequest) request;
String ContextPath = Httpservletrequest.getrequesturi ();
Gets the request path that needs to be converted to HTTPS, which is in the XML file
list<string> resultlist = GetList ()
Issecure () to detect whether the request is HTTPS
if (Httpservletrequest.issecure () && resultlist.contains (ContextPath)) {
This is used to do page redirection, and if the path needs to be switched to HTTPS, redirect
Response.sendredirect (...);
}
else {
Chain.dofilter (request, response);
}
Return
}




<filter>
<filter-name>Redirect</filter-name>
<filter-class>com.abc.def.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Redirect</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2 JS Method
if (Window.location.protocol = = "http:") {
if (window.location.replace) {
Window.location.replace ("https" + WINDOW.LOCATION.HREF.SUBSTR (4));
} else {
window.location.href = "https" + WINDOW.LOCATION.HREF.SUBSTR (4)
}
}
3 Tomcat Main configuration:
<connector connectiontimeout= "20000" port= "protocol=" http/1.1 "redirectport=" 443
<!--configured with 443 ports, KeyStore path, and password-->
<connector port= "443" sslenabled= "true" Clientauth= "false" keystorefile= "D:/a/b/tomcat.keystore" keystorePass= " 222555 "maxthreads=" protocol= "http/1.1" scheme= "https" secure= "true" sslprotocol= "TLS"/>
<connector port= "8009" protocol= "ajp/1.3" redirectport= "443"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.