public static boolean forwardToPrevious(final HttpServletRequest request, final HttpServletResponse response)
  	throws ServletException, IOException
	{
  final String referrer = request.getHeader(REFERRER);
  if (null == referrer)
  {
  	return false;
  }
  final String contextPath = request.getContextPath();
  if (referrer.contains(contextPath))
  {
  	/* @formatter:off */
  	final String previousPage = referrer.substring(referrer
                                        .indexOf(contextPath) +
                                        contextPath.length());
  	final String requestUri = request.getRequestURI();
  	final String requestUriWithoutContextPath =
    requestUri.contains(contextPath) ?
      requestUri.substring(requestUri
                	.indexOf(contextPath) +
                	contextPath.length()) :
      requestUri;
  	/* @formatter:on */
  	if (requestUriWithoutContextPath.equals(previousPage))
  	{
    return false;
  	}
  	request.getRequestDispatcher(previousPage)
    	.forward(request, response);
  	return true;
  }
  return false;
	}