public static void redirect(HttpServletRequest request, HttpServletResponse response,
                               String url) throws IOException {
        String redirectUrl;

        if (url.startsWith("/")) {
            redirectUrl = request.getContextPath() + url;
        } else {
            redirectUrl = url;
        }

        logger.debug("Redirecting to URL: {}", redirectUrl);

        response.sendRedirect(redirectUrl);
    }
public static void redirect ( HttpServletRequest request , HttpServletResponse response , String url ) throws IOException { String redirectUrl ; if ( url . startsWith ( "/" ) ) { redirectUrl = request . getContextPath ( ) + url ; } else { redirectUrl = url ; } logger . debug ( "Redirecting to URL: {}" , redirectUrl ) ; response . sendRedirect ( redirectUrl ) ; }
Redirects to the specified URL. If the URL starts with '/', the request context path is added.

@param request   the request
@param response  the response
@param url       the URL to redirect to