Programming > Java

https/http 접속확인 방법

check http or https in java

String protocol = request.getProtocol();

http HTTP/1.1
https SSLv3


boolean secure = request.isSecure();
 

http false
https true

check http or https in javascript

1) javascript에서 URL 파싱
  1. 입력 : http://localhost:8888/index.jsp?mc=xxxx&var=%ED%95%9C%EA%B8%80%EC%9E%85%EB%A0%A5
  2. 결과 : 아래 각각의 변수를 출력한 결과
  • window.location.protocol = http:
  • window.location.host = localhost:8888
  • window.location.pathname = /index.jsp
  • window.location.search = ?mc=xxxx&var=%ED%95%9C%EA%B8%80%EC%9E%85%EB%A0%A5
1) http to https : reload

※  protocol을 확인 후 https로 변경후 reload한다.

if(window.location.protocol != "https:") {
    window.location.protocol = "https:";
    window.location.reload();

    location.href = 'https:' + window.location.href.substring(window.location.protocol.length);

    location.href = location.href.replace(/^http:/, 'https:')    
}