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:com.me.Controller.AddBookController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ModelAndView mav = new ModelAndView();
    String action = request.getParameter("action");
    if (action.equals("get")) {
        String number = request.getParameter("noOfBooks");
        int noOfBooks = Integer.parseInt(number);
        if (noOfBooks > 0) {
            mav.addObject("numberBooks", noOfBooks);
            mav.setViewName("Books");
        }//from www  .  j  a  v  a  2s. c om
    } else if (action.equals("post")) {
        DAO dao = new DAO();
        Connection conn = null;
        PreparedStatement preparedStatement = null;
        try {

            conn = dao.getConnection();
            String[] isbn = request.getParameterValues("isbn");
            String[] title = request.getParameterValues("title");
            String[] authors = request.getParameterValues("authors");
            String[] price = request.getParameterValues("Price");
            String insertQuery = "insert into books(isbn,title,authors,price)" + "values(?,?,?,?)";
            int count = 0;
            for (int i = 0; i < isbn.length; i++) {

                preparedStatement = conn.prepareStatement(insertQuery);
                preparedStatement.setString(1, isbn[i]);
                preparedStatement.setString(2, title[i]);
                preparedStatement.setString(3, authors[i]);
                preparedStatement.setFloat(4, Float.parseFloat(price[i]));
                int result = preparedStatement.executeUpdate();
                count++;
            }
            mav.addObject("noOfRecords", count);
            mav.setViewName("Result");
        } finally {
            dao.closeConnection(conn);
            dao.closeStatement(preparedStatement);
        }

    }

    return mav;
}

From source file:com.mycompany.springmvcaccount.controller.UserFormController.java

@RequestMapping(value = "/registerForm")
public ModelAndView showFormRegister() {
    ModelAndView mv = new ModelAndView();
    mv.setViewName("registerBootstrap");
    mv.addObject("user", new User());
    mv.addObject("countries", countries);
    return mv;/*from w  w  w.j av a2  s.co  m*/
}

From source file:com.ut.healthelink.controller.productSuiteController.java

/**
 * The '' request will display the product suite information page.
 *//*w  ww  .j  ava 2s .c o m*/
@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView productSuite() throws Exception {

    ModelAndView mav = new ModelAndView();
    mav.setViewName("/productSuite");
    mav.addObject("pageTitle", "Product Suite");
    return mav;
}

From source file:com.simple.app.controller.MainController.java

@RequestMapping(value = "/index")
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    System.out.println("-------");
    ModelAndView mv = new ModelAndView();
    mv.addObject("message", "Hello World!");
    mv.setViewName("myblog/index");
    return mv;//from  w  w w .  j  a  va2s. c  om
}

From source file:com.me.controller.AddToDb.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest hsr, HttpServletResponse hsr1)
        throws Exception {

    ModelAndView mv = new ModelAndView();

    String[] isbnVal = (String[]) hsr.getParameterValues("isbn");
    String[] titleVal = (String[]) hsr.getParameterValues("bookTitle");
    String[] authorVal = (String[]) hsr.getParameterValues("author");
    String[] priceVal = (String[]) hsr.getParameterValues("price");

    addBooksDAO.addBook(isbnVal, titleVal, authorVal, priceVal);

    mv.setViewName("Success");
    return mv;//from   ww  w. j  a  va2 s .c om
}

From source file:com.web.mavenproject6.other.GlobalExceptionHandler.java

@ExceptionHandler(Exception.class)
public ModelAndView handleIOException(HttpServletRequest req, Map<String, Object> model, Exception ex) {
    ModelAndView mav = new ModelAndView();
    mav.addObject("exception", ex);
    mav.addObject("url", req.getRequestURL());
    mav.setViewName("thy/error/Exception");
    return mav;//www . j  a v a2s .c om
}

From source file:org.duracloud.account.app.controller.HomeController.java

@RequestMapping(value = { "/index.html", "/", "", "/home.html", "/index", "/home" })
public ModelAndView home() {
    log.info("serving up the home page at {}", System.currentTimeMillis());
    ModelAndView mav = new ModelAndView();
    mav.setViewName(HOME_VIEW_ID);// w  ww  .j  a v  a  2  s .  c  om
    return mav;
}

From source file:com.mycompany.springmvcaccount.controller.UserController.java

@RequestMapping(value = "/showUser")
public ModelAndView showListUser() {

    ModelAndView mv = new ModelAndView();
    mv.addObject("listUser", this.userService.showAllUser());
    mv.setViewName("showUser");
    return mv;//w  ww  .  j  a v  a  2 s.  c om
}

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

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

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

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

    ModelAndView retval = new ModelAndView();
    Session sess = HibernateUtil.getSessionFactory().openSession();

    try {/*from   w  ww.j ava2s.  c  o  m*/
        Query q = sess.createQuery("FROM Category");
        retval.addObject("categories", q.list());
    } finally {
        sess.close();
    }

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