URL Forwarding With Spring MVC

Asked

Viewed 1,330 times

10

I want to put in my project access a page in a subdirectory of views. Type views/pessoa/criar.jsp.

How can I write a controller who goes to this page?

I’m using Spring MVC 3 and InternalResourceViewResolver.

I tried with redirect and I couldn’t.

  • In your controller’s Return it is only by the jsp name you want it to be called. Check this page here: http://www.caelum.com.br/apostila-java-web/spring-mvc/#11-5-a-logica-ola-mundo

  • My answer managed to help you?

2 answers

1

On the return of controller, if everything is already configured correctly - /WEB-INF/views/ prefix and . jsp as suffix - just return "pessoa/criar".

  • I believe you’ve changed... .jsp is the suffix and /WEB-INF/views/ is the prefix, no?

1

I’ll put two methods of a controller containing the most common ways to do this.

In code it would be something along those lines:

@Controller
public class MainController {


    @RequestMapping(value = "/", method = RequestMethod.GET)
    public ModelAndView getdata() {
    List<String> list = getList();

        //return back to index.jsp
        ModelAndView model = new ModelAndView("index");
        model.addObject("lists", list);

        return model;
    }

    @RequestMapping(value = "/listagem", method = RequestMethod.GET)
    public String listagem() {
        return "listagem";
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.