Example usage for org.springframework.web.servlet ModelAndView ModelAndView

List of usage examples for org.springframework.web.servlet ModelAndView ModelAndView

Introduction

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

Prototype

public ModelAndView() 

Source Link

Document

Default constructor for bean-style usage: populating bean properties instead of passing in constructor arguments.

Usage

From source file:per.mnn.controller.CategoryController.java

@RequestMapping(value = "/category", method = RequestMethod.GET)
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse respond) {

    ModelAndView retval = new ModelAndView();
    HttpSession httpSess = request.getSession();
    Session sess = HibernateUtil.getSessionFactory().openSession();

    try {//from  w  ww .ja  va  2 s  .  c  om
        Query query = sess.createQuery("FROM Category");
        retval.addObject("categories", query.list());

        String name = request.getQueryString();
        if (name != null && !name.isEmpty()) {
            for (Category item : (List<Category>) query.list()) {
                if (item.getName().equals(name.replace("%20", " "))) {
                    httpSess.setAttribute("selectedCategory", item);
                    query = sess.createQuery("FROM Product as p WHERE p.category.id = :id");
                    query.setInteger("id", item.getId());
                    httpSess.setAttribute("categoryProducts", query.list());
                    break;
                }
            }
        }
    } finally {
        sess.close();
    }

    retval.setViewName("category");
    return retval;
}

From source file:jp.pigumer.app.Hello.java

@RequestMapping("/hello")
public ModelAndView hello(@AuthenticationPrincipal User user) {
    ModelAndView mv = new ModelAndView();
    mv.addObject("user", user.getUsername());
    mv.setViewName("hello");
    return mv;//from w  ww  . j  a va  2  s.c o m
}

From source file:com.controller.PanelController.java

@RequestMapping("panel.htm")
public ModelAndView getPanel(HttpServletRequest request) {
    sesion = request.getSession();// ww  w .  j  av a 2  s  . c  om
    ModelAndView mav = new ModelAndView();
    String mensaje = null;

    if (sesion.getAttribute("usuario") == null) {
        mav.setViewName("login/login");

    } else {
        sesionUser = sesion.getAttribute("usuario").toString();
        if (sesion.getAttribute("tipoUsuario").toString().compareTo("Administrador") == 0) {
            mav.setViewName("viewsAdmin/panelAdmin");
            System.out.println("el usuario es administrador");
        } else {
            mav.setViewName("panel/panel");
        }
    }
    return mav;

}

From source file:com.neu.edu.servlet.homeController.java

@Override
public ModelAndView handleRequest(HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception {
    HttpSession session = hsr.getSession();
    String action = hsr.getParameter("action");
    ModelAndView mv = new ModelAndView();

    if (action.equals("loginpage")) {
        mv.setViewName("login");
    }//from w  ww. java 2 s  .  co  m

    else if (action.equals("login")) {
        String uname = hsr.getParameter("username");
        String pass = hsr.getParameter("password");
        Customer c = customerDAo.verifyUser(uname, pass);

        if (c != null) {
            session.setAttribute("customerId", c.getCustomerID());
            session.setAttribute("customerName", c.getName());

            mv.setViewName("index");
        } else {
            mv.addObject("error", "true");
            mv.setViewName("login");
        }
    }

    else if (action.equals("logout")) {
        session.invalidate();
        mv.setViewName("index");
    }

    return mv;
}

From source file:team.curise.controller.GetController.java

@RequestMapping("/depositPayTable")
public ModelAndView depositPayTable() {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("/depositPayTable");
    return mv;//w  w  w .  j a v  a 2s .co  m
}

From source file:web.SecurityController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    ModelAndView model = new ModelAndView();

    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }//from www.ja  v  a 2  s  . c o m

    if (logout != null) {
        model.addObject("msg", "You've been logged out successfully.");
    }

    model.setViewName("login");

    return model;
}

From source file:br.com.helio.pocspringmvc.web.ProdutoController.java

@RequestMapping(value = "/lista", method = RequestMethod.GET)
public ModelAndView showPersons() {
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.addObject("produtos", produtService.findAll());
    modelAndView.setViewName("produto/lista");

    return modelAndView;
}

From source file:com.gemtastic.lillakammaren.controller.IndexController.java

@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView index() throws IOException {
    this.repository = ProductRepository.getInstance();
    ModelAndView model = new ModelAndView();
    model.setViewName("index");
    model.addObject("categories", repository.getAllCategories());
    model.addObject("cartsize", cart.getCartSize());
    return model;
}

From source file:org.owasp.webgoat.controller.Login.java

/**
 * <p>login.</p>/*w ww  .j a v a2 s.c  o  m*/
 *
 * @param error a {@link java.lang.String} object.
 * @param logout a {@link java.lang.String} object.
 * @return a {@link org.springframework.web.servlet.ModelAndView} object.
 */
@RequestMapping(value = "login.mvc", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    ModelAndView model = new ModelAndView();
    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }

    if (logout != null) {
        model.addObject("msg", "You've been logged out successfully.");
    }
    model.setViewName("login");

    return model;

}

From source file:CRM.web.MishaSecurityController.java

@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
        @RequestParam(value = "logout", required = false) String logout) {

    ModelAndView model = new ModelAndView();

    if (error != null) {
        model.addObject("error", "Invalid username and password!");
    }//from w  w w  .  ja va  2 s. c om
    if (logout != null) {
        model.addObject("msg", "You have successfully logged out.");
    }

    model.setViewName("login");

    return model;
}