code: private void redirectToTarget(HttpServletRequest req, HttpServletResponse res, String link, boolean isPermanent)
      throws IOException, CmsResourceInitException {
  
          CmsResourceInitException resInitException = new CmsResourceInitException(getClass());
          if (res != null) {
              // preserve request parameters for the redirect
              String query = req.getQueryString();
              if (query != null) {
                  link += "?" + query;
              }
              // disable 404 handler
              resInitException.setClearErrors(true);
              if (isPermanent) {
                  res.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
                  res.setHeader("Location", link);
              } else {
                  res.sendRedirect(link);
              }
          }
          throw resInitException;
      }
docs: Helper method for sending a redirect to a new URI.<p>
  
  @param req the current request
  @param res the current response
  @param link the redirect target
  @param isPermanent if true, sends a 'moved permanently' redirect
  
  @throws IOException
  @throws CmsResourceInitException