Search⌘ K

View

Explore how Spring MVC handles views by mapping logical view names to JSP files using view resolvers. Learn to configure prefix and suffix in application properties, and see how the dispatcher servlet renders JSP pages securely within the WEB-INF directory.

When a controller or handler returns a response back to the dispatcher servlet, it is either shown as it is to the user (if the @ResponseBody annotation is present), or a view is called.

In real world applications, we do not return String responses back to the user. We redirect the user to a view or JSP.

Redirecting to a view

Say, we want a request to "/" to be redirected to main-menu.jsp. We can return the view name as follows:

Java
@RequestMapping(value = "/")
public String welcome() {
return "main-menu";
}

The return value main-menu will be treated as the name of a view now, because we have removed the @ResponseBody annotation from the ...