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:controller.blogsidebar.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {

    //System.out.println("test");

    Session s = HibernateUtil.getSessionFactory().getCurrentSession();
    s.beginTransaction();/*  w w  w  .j a  v a2s  .  c om*/

    ModelAndView mav = new ModelAndView("blog-sidebar-v1");
    dummy login = (dummy) command;

    if ((login.getl3() == null) && (login.gets6().equals("doctor"))) {

        // if(login.gets6().equals("doctor")){

        Logintable l = new Logintable();
        l.setCnic(login.getl1());
        long j = login.getl1();
        int k = (int) j;

        //  long contact = login.getl6();
        // int cont = (int) contact;
        l.setPassword(login.gets2());
        l.setStatus(login.gets6());

        Doctors doc = new Doctors();
        doc.setId(k);
        doc.setDoctorname(login.gets1());
        doc.setDoctordepartment(login.gets5());

        //doc.setContact(login.getl6());
        doc.setEmail(login.gets7());
        doc.setCity(login.gets3());
        doc.setAddress(login.gets4());

        long z = login.getl2();
        int v = (int) z;
        doc.setPmdcId(v);

        // Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        // s.beginTransaction();
        s.save(l);
        s.save(doc);

        s.getTransaction().commit();
        return new ModelAndView(new RedirectView("home.htm"));

    }

    if ((login.getl3() == null) && (login.gets6().equals("patient"))) {

        //    Session session2 = HibernateUtil.getSessionFactory().getCurrentSession();
        //session2.beginTransaction();

        Logintable pat = new Logintable();
        pat.setCnic(login.getl8());
        long j = login.getl11();
        int k = (int) j;

        pat.setPassword(login.gets9());
        pat.setStatus(login.gets6());
        pat.setStatus("Patient");

        Patients p = new Patients();
        p.setPid(login.getl8());
        p.setName(login.gets8());
        p.setEmail(login.gets14());
        p.setAddress(login.gets12());
        p.setAge(k);
        p.setPhoneNumber(login.getl9());
        // p.getPhoneNumber(login.);
        p.setEmergencyContact(login.getl10());
        p.setBloodGroup(login.gets13());

        s.save(pat);

        s.save(p);

        s.getTransaction().commit();
        return new ModelAndView(new RedirectView("home.htm"));

    }

    //mv.addObject("photoCommand", photoCommand);

    if (login.getl3() != null) {
        Logintable x = new Logintable();
        long cnic = login.getl3();
        String password = login.gets7();
        //   Session session3 = HibernateUtil.getSessionFactory().getCurrentSession();
        //  session3.beginTransaction();
        // session3.save();
        Query query1 = s.createQuery("from Logintable where cnic = :cnic and password = :password");
        query1.setParameter("cnic", cnic);
        query1.setParameter("password", password);
        //  HttpSession session = request.getSession();
        //session.setAttribute("scard", password);
        //session3.setAttribute("check", "hello beother");
        // query1.setParameter("password", password);
        List list = query1.list();
        s.getTransaction().commit();
        // String check =  list.get(0).toString();
        if ((list.size() == 0)) {

            return new ModelAndView(new RedirectView("signin.htm"));

        } else {
            request.getSession().setAttribute("scard", "hello");

            return new ModelAndView(new RedirectView("home.htm"));
        }

        // session3.getTransaction().commit();
        //  session3.

    }

    //session.close();

    //return (mav);
    return new ModelAndView(new RedirectView("home.htm"));

}

From source file:fm.last.citrine.web.AdminController.java

public ModelAndView prepareForShutdown(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    schedulerManager.prepareForShutdown();
    return new ModelAndView(new RedirectView("admin.do"));
}

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

/**
 * The onSubmit function receives the modified macro property string and saves it
 * //from ww  w . j  a va 2  s  . c o  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();
    if (Context.isAuthenticated()) {
        CommandObject command = (CommandObject) obj;
        Context.getAdministrationService().saveGlobalProperty(
                new GlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_REPORT_XML_MACROS, command.getMacros()));
        view = getSuccessView();
    }
    return new ModelAndView(new RedirectView(view));
}

From source file:ru.org.linux.poll.VoteController.java

@RequestMapping(value = "/vote.jsp", method = RequestMethod.POST)
public ModelAndView vote(ServletRequest request, @RequestParam("vote") int[] votes,
        @RequestParam("voteid") int voteid) throws Exception {
    Template tmpl = Template.getTemplate(request);

    if (!tmpl.isSessionAuthorized()) {
        throw new AccessViolationException("Not authorized");
    }/*from   w w w . j ava 2  s  .c  o  m*/

    User user = tmpl.getCurrentUser();

    Poll poll = pollDao.getCurrentPoll();
    Topic msg = messageDao.getById(poll.getTopicId());

    if (voteid != poll.getId()) {
        throw new BadVoteException("?     ?");
    }

    if (votes == null || votes.length == 0) {
        throw new BadVoteException("  ");
    }

    if (!poll.isMultiSelect() && votes.length != 1) {
        throw new BadVoteException(
                "? ? ?    ");
    }

    try {
        pollDao.updateVotes(voteid, votes, user);
    } catch (DuplicateKeyException ex) {
        logger.info("Failed to vote", ex);
    }

    return new ModelAndView(new RedirectView(msg.getLink()));
}

From source file:net.mindengine.oculus.frontend.web.controllers.SecureSimpleViewController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    verifyPermissions(request);//www .  ja va  2s .co m
    Map<String, Object> model = null;

    try {
        model = handleController(request);
        if (model != null) {
            if (!model.containsKey("title")) {
                model.put("title", title);
            }
        }
    } catch (RedirectException redirectException) {
        return new ModelAndView(new RedirectView(redirectException.getRedirectUrl()));
    }

    if (view == null)
        throw new Exception("The view is not defined");

    ModelAndView mav = new ModelAndView(view);
    if (model != null)
        mav.addAllObjects(model);

    return mav;
}

From source file:org.openmrs.web.controller.user.PrivilegeFormController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//  w  w w. j  av a 2  s  . c  om
 *
 * @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 {

    HttpSession httpSession = request.getSession();

    String view = getFormView();

    if (Context.isAuthenticated()) {
        Privilege privilege = (Privilege) obj;
        Context.getUserService().savePrivilege(privilege);
        view = getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Privilege.saved");
    }

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

From source file:psiprobe.controllers.datasources.ResetDataSourceController.java

@Override
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    String resourceName = ServletRequestUtils.getStringParameter(request, "resource", null);
    String referer = request.getHeader("Referer");
    String redirectUrl;/* w  w  w . j  a  va2  s.c om*/
    if (referer != null) {
        redirectUrl = referer.replaceAll(replacePattern, "");
    } else {
        redirectUrl = request.getContextPath() + getViewName();
    }

    if (resourceName != null && resourceName.length() > 0) {
        boolean reset = false;
        try {
            reset = getContainerWrapper().getResourceResolver().resetResource(context, resourceName,
                    getContainerWrapper());
        } catch (NamingException e) {
            request.setAttribute("errorMessage", getMessageSourceAccessor()
                    .getMessage("probe.src.reset.datasource.notfound", new Object[] { resourceName }));
            logger.trace("", e);
        }
        if (!reset) {
            request.setAttribute("errorMessage",
                    getMessageSourceAccessor().getMessage("probe.src.reset.datasource.c3p0"));
        }

    }
    logger.debug("Redirected to {}", redirectUrl);
    return new ModelAndView(new RedirectView(redirectUrl));
}

From source file:org.openmrs.web.controller.concept.ConceptClassFormController.java

/**
 * The onSubmit function receives the form/command object that was modified by the input form
 * and saves it to the db//from  w w w . j a  v a 2  s  . c om
 *
 * @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 {

    HttpSession httpSession = request.getSession();

    String view = getFormView();

    if (Context.isAuthenticated()) {
        ConceptClass cc = (ConceptClass) obj;
        Context.getConceptService().saveConceptClass(cc);
        view = getSuccessView();
        httpSession.setAttribute(WebConstants.OPENMRS_MSG_ATTR, "ConceptClass.saved");
    }

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

From source file:net.smartam.leeloo.controller.AuthzController.java

@RequestMapping("/authorize")
public ModelAndView authorize(@ModelAttribute("oauthParams") OAuthParams oauthParams, HttpServletRequest req,
        HttpServletResponse res) throws OAuthSystemException, IOException {

    try {/*  w  ww  . j  a  va  2 s .  co  m*/

        Utils.validateAuthorizationParams(oauthParams);

        res.addCookie(new Cookie("clientId", oauthParams.getClientId()));
        res.addCookie(new Cookie("clientSecret", oauthParams.getClientSecret()));
        res.addCookie(new Cookie("authzEndpoint", oauthParams.getAuthzEndpoint()));
        res.addCookie(new Cookie("tokenEndpoint", oauthParams.getTokenEndpoint()));
        res.addCookie(new Cookie("redirectUri", oauthParams.getRedirectUri()));
        res.addCookie(new Cookie("scope", oauthParams.getScope()));
        res.addCookie(new Cookie("app", oauthParams.getApplication()));

        OAuthClientRequest request = OAuthClientRequest.authorizationLocation(oauthParams.getAuthzEndpoint())
                .setClientId(oauthParams.getClientId()).setRedirectURI(oauthParams.getRedirectUri())
                .setResponseType(ResponseType.CODE.toString()).setScope(oauthParams.getScope())
                .buildQueryMessage();

        return new ModelAndView(new RedirectView(request.getLocationUri()));

    } catch (ApplicationException e) {
        oauthParams.setErrorMessage(e.getMessage());
        return new ModelAndView("get_authz");
    }
}

From source file:com.persistent.cloudninja.controller.UsageController.java

/**
 *  Run metering tasks manually./*  ww w . jav a  2 s  .  c o m*/
 * @return ModelAndView mapped to Usage Page. 
 */
@RequestMapping("RunMeteringManually.htm")
public ModelAndView runMeteringTasks() {
    usageService.runMeteringTasksManually();
    return new ModelAndView(new RedirectView("Metering.htm"));
}