This is a very simple and little function that gets the name of the protocol used when accessing the servlet. Great if you want to construct a URL...
/**
* Returns the protocol name (http/https etc)
*that the request was made with.
*
* @author Johan Känngård, http://dev.kanngard.net
* @param request the request that should be examined.
* @return the protocol string in lowercase
* @see HttpServletRequest#getProtocol()
*/
private String getProtocolName(HttpServletRequest request) {
String s = request.getProtocol().toLowerCase();
return s.substring(0, s.indexOf("/")).toLowerCase();
}