Example usage for javax.servlet.http HttpServletResponse sendRedirect

List of usage examples for javax.servlet.http HttpServletResponse sendRedirect

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse sendRedirect.

Prototype

public void sendRedirect(String location) throws IOException;

Source Link

Document

Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.

Usage

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MaintenanceEventMultiUploadController.java

@RequestMapping(value = "/getAttachmentForEvent.html", method = RequestMethod.GET)
public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) {
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "eventAttachment");
    Entity attachment = attachmentDD.get(ids[0]);
    InputStream is = fileService//w  ww  .  j av  a 2s  .  co m
            .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));

    try {
        if (is == null) {
            response.sendRedirect("/error.html?code=404");
        }

        response.setHeader("Content-disposition",
                "inline; filename=" + attachment.getStringField(TechnologyAttachmentFields.NAME));
        response.setContentType(
                fileService.getContentType(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)));

        int bytes = IOUtils.copy(is, response.getOutputStream());
        response.setContentLength(bytes);

        response.flushBuffer();

    } catch (IOException e) {
        logger.error("Unable to copy attachment file to response stream.", e);
    }
}

From source file:com.gcrm.action.crm.BaseEditAction.java

/**
 * ??/*from  w  ww. ja v a 2 s.  c  om*/
 */
protected void redirectUrl(String url) throws Exception {
    HttpServletResponse response = ServletActionContext.getResponse();
    response.sendRedirect(url);
}

From source file:info.magnolia.cms.servlets.EntryServlet.java

/**
 * Redirect based on the mapping in config/server/.node.xml
 * @param request HttpServletRequest/*from ww w .j  a  v  a2s  . c om*/
 * @param response HttpServletResponse
 * @return <code>true</code> if request has been redirected, <code>false</code> otherwise
 */
private boolean redirect(HttpServletRequest request, HttpServletResponse response) {
    String uri = this.getURIMap(request);
    if (StringUtils.isNotEmpty(uri)) {
        if (!response.isCommitted()) {

            if (uri.startsWith("redirect:")) {
                try {
                    response.sendRedirect(
                            request.getContextPath() + StringUtils.substringAfter(uri, "redirect:"));
                } catch (IOException e) {
                    log.error("Failed to redirect to {}:{}", //$NON-NLS-1$
                            new Object[] { uri, e.getMessage() });
                }
            } else {

                try {
                    request.getRequestDispatcher(uri).forward(request, response);
                } catch (Exception e) {
                    log.error("Failed to forward to {} - {}:{}", //$NON-NLS-1$
                            new Object[] { uri, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
                }
            }
        } else {
            log.warn("Response is already committed, cannot forward to {} (original URI was {})", //$NON-NLS-1$
                    uri, request.getRequestURI());
        }

        return true;
    }
    return false;
}

From source file:io.muic.ooc.webapp.servlet.EditServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String username = request.getParameter("usernameEdit");
    String password = request.getParameter("passwordEdit");
    System.out.println("YEAHHHHHHHH" + username);
    System.out.println("YEAHHHHHHHH" + password);
    String digest = DigestUtils.md5Hex(password);
    try {/*from  ww w  .  j  a  v  a 2 s.  com*/
        mySQLService.editDataBase(username, digest);
    } catch (Exception e) {

    }
    response.sendRedirect("/");
}

From source file:cn.vlabs.umt.ui.actions.ActivationPrimaryAction.java

/**
 * ??//from   w w  w . j a  v a 2 s  .  c  o m
 * */
public ActionForward confirmChangeLoginEmail(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    ActivationForm data = (ActivationForm) form;
    boolean isValid = getTokenService().isValid(data.getTokenid(), data.getRandom(),
            Token.OPERATION_COMFIRM_PRIMARY_EMAIL);
    //token
    if (!isValid) {
        response.sendRedirect(ShowPageAction.getMessageUrl(request, "active.login.email.fail"));
        return null;
    }
    Token token = getTokenService().getTokenById(data.getTokenid());
    User user = getUserService().getUserByUid(token.getUid());
    getTokenService().toUsed(token.getId());
    AbstractDoActivation doActivation = new DoActivationServiceForPrimaryConfirm(request, response, token, user,
            data, mapping);
    return doActivation.doActivation();

}

From source file:at.gv.egiz.pdfas.web.helper.PdfAsHelper.java

public static void gotoError(ServletContext context, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (PdfAsHelper.getFromDataUrl(request)) {
        response.sendRedirect(generateErrorURL(request, response));
    } else {/*  w ww.  ja  va  2 s  . c o  m*/
        RequestDispatcher dispatcher = context.getRequestDispatcher(PDF_ERROR_PAGE);
        dispatcher.forward(request, response);
    }
}

From source file:com.qcadoo.mes.cmmsMachineParts.controller.MachinePartMultiUploadController.java

@RequestMapping(value = "/getAttachment.html", method = RequestMethod.GET)
public final void getAttachment(@RequestParam("id") final Long[] ids, HttpServletResponse response) {
    DataDefinition attachmentDD = dataDefinitionService.get("cmmsMachineParts", "machinePartAttachment");
    Entity attachment = attachmentDD.get(ids[0]);
    InputStream is = fileService/*from  w  w  w . j a v  a 2 s .c  o  m*/
            .getInputStream(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT));

    try {
        if (is == null) {
            response.sendRedirect("/error.html?code=404");
        }

        response.setHeader("Content-disposition",
                "inline; filename=" + attachment.getStringField(TechnologyAttachmentFields.NAME));
        response.setContentType(
                fileService.getContentType(attachment.getStringField(TechnologyAttachmentFields.ATTACHMENT)));

        int bytes = IOUtils.copy(is, response.getOutputStream());
        response.setContentLength(bytes);

        response.flushBuffer();

    } catch (IOException e) {
        logger.error("Unable to copy attachment file to response stream.", e);
    }
}

From source file:pivotal.au.se.gemfirexdweb.controller.ConstraintController.java

@RequestMapping(value = "/constraints", method = RequestMethod.POST)
public String performConstraintAction(Model model, HttpServletResponse response, HttpServletRequest request,
        HttpSession session) throws Exception {
    String schema = null;/*from   w w w .  j a v a  2s  .  c  om*/
    Result result = new Result();

    if (session.getAttribute("user_key") == null) {
        logger.debug("user_key is null new Login required");
        response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
        return null;
    } else {
        Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key"));
        if (conn == null) {
            response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
            return null;
        } else {
            if (conn.isClosed()) {
                response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login");
                return null;
            }
        }

    }

    logger.debug("Received request to perform an action on the constraints");

    String selectedSchema = request.getParameter("selectedSchema");
    logger.debug("selectedSchema = " + selectedSchema);

    if (selectedSchema != null) {
        schema = selectedSchema;
    } else {
        schema = (String) session.getAttribute("schema");
    }

    logger.debug("schema = " + schema);

    ConstraintDAO conDAO = GemFireXDWebDAOFactory.getConstraintDAO();

    List<Constraint> cons = null;

    cons = conDAO.retrieveConstraintList(schema, (String) request.getParameter("search"),
            (String) session.getAttribute("user_key"));

    model.addAttribute("search", (String) request.getParameter("search"));
    model.addAttribute("cons", cons);
    model.addAttribute("records", cons.size());
    model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key")));

    model.addAttribute("chosenSchema", schema);

    // This will resolve to /WEB-INF/jsp/constraints.jsp
    return "constraints";

}

From source file:MyServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    //redirect the user depending on the value of the 'go' param
    String destination = getInitParameter("go");
    String contextPath = request.getContextPath();

    if (destination == null || destination.equals(""))
        throw new ServletException("Missing or invalid 'go' parameter in " + getClass().getName());

    if (destination.equals("weather"))
        //ensure URL rewriting
        response.sendRedirect(response.encodeRedirectURL(contextPath + "/weather"));

    if (destination.equals("maps"))
        //ensure URL rewriting
        response.sendRedirect(response.encodeRedirectURL(contextPath + "/maps"));
}

From source file:be.fedict.eid.dss.webapp.ProtocolEntryServlet.java

private void error(HttpServletRequest request, HttpServletResponse response, String errorMessage, Throwable t)
        throws IOException {

    LOG.error("Protocol error: " + errorMessage, t);
    request.getSession().setAttribute(this.protocolErrorMessageSessionAttributeInitParam, errorMessage);
    response.sendRedirect(request.getContextPath() + this.protocolErrorPageInitParam);
}