Example usage for org.springframework.web.servlet.view RedirectView RedirectView

List of usage examples for org.springframework.web.servlet.view RedirectView RedirectView

Introduction

In this page you can find the example usage for org.springframework.web.servlet.view RedirectView RedirectView.

Prototype

public RedirectView(String url) 

Source Link

Document

Create a new RedirectView with the given URL.

Usage

From source file:com.googlecode.psiprobe.controllers.system.AdviseGarbageCollectionController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean finalization = ServletRequestUtils.getBooleanParameter(request, "fin", false);

    String referer = request.getHeader("Referer");
    String redirectUrl;/*from   w  w  w. j  a v a2s.  co m*/
    if (referer != null) {
        redirectUrl = referer.replaceAll(replacePattern, "");
    } else {
        redirectUrl = request.getContextPath() + getViewName();
    }
    if (finalization) {
        Runtime.getRuntime().runFinalization();
        logger.debug("Advised finalization");
    } else {
        Runtime.getRuntime().gc();
        logger.debug("Advised Garbage Collection");
    }
    logger.debug("Redirected to " + redirectUrl);
    return new ModelAndView(new RedirectView(redirectUrl));
}

From source file:com.googlecode.psiprobe.controllers.deploy.UndeployContextController.java

protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    try {/* w  w  w .  ja v a2 s .  c  o  m*/
        if (request.getContextPath().equals(contextName)) {
            throw new IllegalStateException(
                    getMessageSourceAccessor().getMessage("probe.src.contextAction.cannotActOnSelf"));
        }

        getContainerWrapper().getTomcatContainer().remove(contextName);

    } catch (Exception e) {
        request.setAttribute("errorMessage", e.getMessage());
        logger.error(e);
        return new ModelAndView(
                new InternalResourceView(getFailureViewName() == null ? getViewName() : getFailureViewName()));
    }
    return new ModelAndView(new RedirectView(request.getContextPath() + getViewName()));
}

From source file:net.sourceforge.subsonic.controller.SetHotController.java

protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    Integer id = ServletRequestUtils.getIntParameter(request, "id");
    Integer flag = ServletRequestUtils.getIntParameter(request, "flag");

    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    String username = securityService.getCurrentUsername(request);

    if (flag == 1) {
        hotService.setAlbumHotFlag(username, mediaFile);
    } else {/*from w w w.j a  v  a  2  s .c om*/
        hotService.deleteAlbumHotFlag(mediaFile);
    }

    String url = "main.view?id=" + id;

    return new ModelAndView(new RedirectView(url));
}

From source file:org.openmrs.web.controller.report.ReportDataListController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//from www  .ja v a 2s  .co  m
 * 
 * @see org.springframework.web.servlet.mvc.SimpleFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 */
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object obj,
        BindException errors) throws Exception {

    String view = getFormView();

    return new ModelAndView(new RedirectView(view));
}

From source file:cherry.foundation.springmvc.SecureTestController.java

@RequestMapping(params = "redirect")
public ModelAndView redirect(Authentication auth, Locale locale, SitePreference sitePref,
        HttpServletRequest request, HttpServletResponse response) {
    assertNotNull(auth);//from  w w  w. j a  v  a  2  s .com
    assertNotNull(locale);
    assertNotNull(sitePref);
    assertNotNull(request);
    assertNotNull(response);
    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView("/secure/text"));
    return mav;
}

From source file:net.sourceforge.subsonic.controller.PodcastReceiverAdminController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    Integer channelId = ServletRequestUtils.getIntParameter(request, "channelId");

    if (request.getParameter("add") != null) {
        String url = StringUtils.trim(request.getParameter("add"));
        podcastService.createChannel(url);
        return new ModelAndView(new RedirectView("podcastChannels.view"));
    }/*from ww w .  j  a  v a2  s. co  m*/
    if (request.getParameter("downloadEpisode") != null) {
        download(StringUtil.parseInts(request.getParameter("downloadEpisode")));
        return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
    }
    if (request.getParameter("deleteChannel") != null) {
        podcastService.deleteChannel(channelId);
        return new ModelAndView(new RedirectView("podcastChannels.view"));
    }
    if (request.getParameter("deleteEpisode") != null) {
        for (int episodeId : StringUtil.parseInts(request.getParameter("deleteEpisode"))) {
            podcastService.deleteEpisode(episodeId, true);
        }
        return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
    }
    if (request.getParameter("refresh") != null) {
        if (channelId != null) {
            podcastService.refreshChannel(channelId, true);
            return new ModelAndView(new RedirectView("podcastChannel.view?id=" + channelId));
        } else {
            podcastService.refreshAllChannels(true);
            return new ModelAndView(new RedirectView("podcastChannels.view"));
        }
    }

    return new ModelAndView(new RedirectView("podcastChannels.view"));
}

From source file:org.openmrs.module.pmtct.web.controller.UpdatePatientInformationController.java

/**
 * @see org.springframework.web.servlet.mvc.ParameterizableViewController#handleRequestInternal(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *///from  w w  w .  j av a2s .  c  om
@SuppressWarnings({ "deprecation" })
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    if (Context.getAuthenticatedUser() == null)
        return new ModelAndView(new RedirectView(request.getContextPath() + "/login.htm"));

    Patient p = null;

    ModelAndView mav = new ModelAndView();
    mav.setView(new RedirectView(getViewName() + "?patientId=" + request.getParameter("patientId")));

    try {

        //         config = PMTCTConfiguration.getInstance(request.getRealPath(PMTCTConstants.CONFIGURATION_FILE_LOC));
        //         request.getSession().setAttribute("enableModification", "" + config.isModificationEnabled());
        //         constants = config.getConstants();

        request.getSession().setAttribute("pmtctModuleConfigured", "" + PMTCTConfigurationUtils.isConfigured());

        p = Context.getPatientService().getPatient(Integer.parseInt(request.getParameter("patientId")));
        //         PersonService ps = Context.getPersonService();
        //BIRTHDATE_ATTRIBUTE
        //p.setBirthdate(Context.getDateFormat().parse(request.getParameter("birthdate")));
        //p.setGender(request.getParameter("addGender"));

        if (request.getParameter("formAttribute") != null)
            p = updatePersonAttributes(request, p);
        //         if (request.getParameter("formAddress") != null)
        //            p = updatePersonAddress(request, p);

        //saving the changes
        Context.getPatientService().updatePatient(p);

        log.info("Information updated successifully for patient with id " + request.getParameter("patientId"));

        String msg = getMessageSourceAccessor().getMessage("pmtct.general.saveSuccess");
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, msg);

        //refreshing the patient object
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("patient", p);
        //         model.put("location", p.getPersonAddress());

        //         request.getSession().setAttribute("model", model);

        //         because the gender cant be updated from here, no need to check if the patient is male
        //         if(p.getGender().compareToIgnoreCase("M")==0)
        //            mav.setView(new RedirectView(request.getContextPath()+"/patientDashboard.form?patientId=" + request.getParameter("patientId")));

    } catch (Exception e) {
        log.error("An error occured when trying to update information for patient with id "
                + request.getParameter("patientId"));
        e.printStackTrace();

        String msg = getMessageSourceAccessor().getMessage("pmtct.general.notSaved");
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, msg);

    }

    return mav;
}

From source file:com.yahoo.dba.perf.myperf.springmvc.MyPerfBaseController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp)
        throws Exception {
    logger.info("receive url path: " + req.getContextPath() + "," + req.getRequestURI() + ", "
            + req.getServletPath() + ", parameters: " + req.getQueryString());

    AppUser user = retrieveAppUser(req);

    if (this.requireLogin && user == null)//check if user valid when require login
    {/*from  ww  w.  j  a  v  a2  s . c om*/
        if (this.nosessView != null)
            return new ModelAndView(new RedirectView(nosessView));
        return respondFailure("Session expired. Please relogin and try again.", req);
    } else if (this.requireLogin && !user.isVerified()) {
        //TODO use a message view
        return this.respondFailure(
                "New user request has not been verified by administrator yet. Please contact administrator by email "
                        + this.frameworkContext.getMyperfConfig().getAdminEmail() + ".",
                req);
    }

    return handleRequestImpl(req, resp);
}

From source file:org.openmrs.module.phrjournal.web.controller.NewEntryController.java

@RequestMapping(value = "/module/phrjournal/create_entry", method = RequestMethod.POST)
public ModelAndView saveEntry(@RequestParam("title") String title, @RequestParam("content") String content,
        HttpServletRequest request) {//from  w  w  w .j  a  va 2s  .co m
    if (title.trim().equals("") || title == null) {
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "Please choose a title.");
        request.getSession().setAttribute("content", content);
        shouldReset = false;
        return new ModelAndView(new RedirectView("new_entry.form"));
    } else if (content.trim().equals("") || content == null) {
        request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR,
                "There was no text in your journal entry.");
        request.getSession().setAttribute("title", title);
        shouldReset = false;
        return new ModelAndView(new RedirectView("new_entry.form"));
    }
    JournalEntry entry = new JournalEntry(title, content);
    entry.setCreator(Context.getAuthenticatedUser().getPerson());
    Context.getService(JournalEntryService.class).saveJournalEntry(entry);
    return new ModelAndView(new RedirectView("journal.form"));

}

From source file:org.iwethey.forums.web.post.PostController.java

/**
 * Toggle expanded history settings.//from   w ww  . jav a  2 s . c o m
 * <p>
 */
public ModelAndView expandHistory(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int id = RequestUtils.getRequiredIntParameter(request, "postid");
    Post post = getPostManager().getPostById(id);
    int index = RequestUtils.getRequiredIntParameter(request, "index");

    ExpandedHistory expanded = ExpandedHistory.getExpandedHistory(request);
    expanded.toggle(post, index);

    return new ModelAndView(new RedirectView(request.getHeader("referer")));
}