Home How to use SpringMVC without Controller using ViewControllerRegistry with addViewController() and so on?
Reply: 0

How to use SpringMVC without Controller using ViewControllerRegistry with addViewController() and so on?

user5383
1#
user5383 Published in September 19, 2018, 9:19 am

I am reading followoing article:

https://www.concretepage.com/spring-4/spring-4-mvc-without-controller-using-viewcontrollerregistry-with-addviewcontroller-addredirectviewcontroller-and-addstatuscontroller-example

There is mapping configuration provided:

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/home").setViewName("myhome");
    registry.addViewController("/hello").setViewName("helloworld");
    registry.addRedirectViewController("/home", "/hello");
    registry.addStatusController("/detail", HttpStatus.BAD_REQUEST);        
} 

The author writes:

  1. When we access URL /hello then helloworld.jsp will run.
  2. When we access URL /home then helloworld.jsp will run because it will be redirected to the URL /hello.
  3. When we access URL /detail then we will get header response with 400 HTTP status code.

Thus the line

registry.addViewController("/home").setViewName("myhome");

is useless?

Also in other tutorial I've found following configuration:

 @Override
 public void addViewControllers(final ViewControllerRegistry registry) {
     super.addViewControllers(registry);
     registry.addViewController("/")
            .setViewName("forward:/index");
     registry.addViewController("/index");
     registry.addViewController("/securedPage");
 }


registry.addViewController("/")
                .setViewName("forward:/index");

This line is clear. It means if I try to access root url application retuns index.jsp

But what the meaning of the

registry.addViewController("/index");
registry.addViewController("/securedPage");

?

share|improve this question

1 Answer 1

active oldest votes
up vote 2 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.487673 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO