하은양 믿음군 효실맘 호홍홍집s

jsp http를 https로 전환 본문

가벼운 배움/jsp

jsp http를 https로 전환

호홍홍집 2016. 5. 2. 09:53

String chkRequestScheme = request.getScheme();
 String chkRequestServerName = request.getServerName();
 String chkRequestServerPort = request.getServerPort()+"";
 String sWEBHOST = request.getServerName();
  
 if(chkRequestServerPort == null || chkRequestServerPort.equals("80")) chkRequestServerPort = "";
 else chkRequestServerPort = ":"+chkRequestServerPort;

 String chkServletForwardURI = (request.getAttribute("javax.servlet.forward.request_uri")==null?"":request.getAttribute("javax.servlet.forward.request_uri")).toString();
 String chkRequestQueryString = (request.getQueryString()==null?"":request.getQueryString());

 if(chkRequestScheme.indexOf("https") < 0 && !sWEBHOST.contains("onezero.kr")){
  String chkHttpUrl = "https://"+chkRequestServerName+chkRequestServerPort+chkServletForwardURI;
  if(chkServletForwardURI.equals("")) chkHttpUrl = request.getRequestURL().toString();
  String sChangeHttpsUrl = chkHttpUrl.replaceAll("http://","https://");
  if(!chkRequestQueryString.equals("")) sChangeHttpsUrl += "?"+chkRequestQueryString;
  response.sendRedirect(sChangeHttpsUrl);
  return;
 }