I wrote a servlet in Java and I would like to know if the request to that servlet was executed using HTTP or HTTPS.
I thought I can use request.getProtocol()
HttpSerlvetRequest.isSecure() is the answer. The ServletContainer is responsible for returning true in the following cases:
The Container should also make this request attributes available when the request is received on https:
https and http runs on different ports. So you can get the port from the request and know from which port the request came and so that you can know the protocol. int port=request.getServerPort();
You can't reliably depend on port numbers.
But you can depend on the scheme:
Use: request.getScheme() to see if it is https
.
If it is then it is secure connection.
I believe this should work regardless of Tomcat version
isSecure. Be sure to check the inherited methods.