Reputation: 181
I want to redirect my page http://
to https://
in jsp.
I have some code with me, but it is giving some problems.
<%
String req_protocol = request.getProtocol().toLowerCase();
String convertHttps = req_protocol.substring(0, req_protocol.indexOf("/")).toLowerCase();
if(convertHttps.equals("http")){
response.sendRedirect("https://xyz.com/signup/signup.jsp");
}
%>
it is giving error page as "infinite loop".
Upvotes: 0
Views: 854
Reputation: 11055
You didn't mention much about your environment, but here's something else to keep in mind.
In addition to what org.life.java mentioned, if you have a reverse proxy in front of your application server (think Apache or Pound in front of Tomcat, Glassfish, etc.), then it is possible that the SSL request is being terminated at the proxy and that the request that gets passed on to the container/application server is just HTTP. In this case, you would typically want to have the proxy server set a header on the request so that the Java side can determine that it is a secure request.
Failure to do that will cause an infinite redirect, since the Java side will always detect that it is HTTP and redirect.
Upvotes: 0
Reputation: 240860
Use request.isSecure()
to determine whether its http://
or https://
This transition is better suited in Filter
or Servlet
rather than jsp
Upvotes: 5