I have a working way to transfer someone to https:
In my program login.jsp, I added a hyperlink "Go to Secure Login". This link is rendered only if the protocol is not secure. I detect this through a method in the backing bean:
public boolean getSecure() {
HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
return request.isSecure();
}
The URL of the link is determined in another method in the backing bean:
public
String getHttps() {
String httpsPort = Props.getProps().getStringProperty("httpsPort");
HttpServletRequest request = (HttpServletRequest)facesContext.getExternalContext().getRequest();
String newpath = "https://"
+ request.getServerName()
+ httpsPort
+ request.getContextPath()
+ "/index.jsp";
return newpath;
}
The method Props.getProps().getStringProperty("httpsPort") gets the port number with a leading : from my properties file. This allows me to migrate the application to a server where https: is configured to a different port.
index.jsp is the page (not jsf) that is coded in web.xml as the welcome page. It contains: <
jsp:forward page="faces/login.jsp"></jsp:forward>
I don't understand why, but if I link to the login.jsp page with the https: protocol, I get an error message "Cannot find FacesContext."