Circular View Path

Source: Internet
Author: User

Recent learning Spring boot has seen this:

Circular view Path [readinglist]: would dispatch back to the current handler URL [/readinglist] again. Check your Viewresolver setup! (Hint:this May is the result of a unspecified view, due to default view name generation.


The reasons are as follows:

when no viewresolver is declared , Spring registers a default viewresolver for you, which is an instance of Jstlview, which inherits from Internalresoureview.

Jstlview is used to encapsulate a JSP or other resource in the same Web application, exposing the model object as a property value for request requests and forwarding the request through Javax.servlet.RequestDispatcher to the specified URL.

Spring believes that the URL of this view can be used to specify specific resources in the same Web application, and can be forwarded by RequestDispatcher.

That is, before page rendering (render), spring attempts to use RequestDispatcher to continue forwarding the request. the following code:

if (Path.startswith ("/")? Uri.equals (Path): Uri.equals (Stringutils.applyrelativepath (URI, Path)) {
    throw new  Servletexception ("Circular View path [" + Path + "]: would dispatch back" + "to the current
                        handler URL [" + URI + "] Again. Check your Viewresolver setup! "+
                        " (Hint:this May is the result of a unspecified view, due to default view name generation.);
}

As you can see from this code, if your view name and your path are the same string, according to spring's forwarding rules, you will be able to forward it to yourself and be trapped in a dead loop. So spring checks this out and throws a Circular view path exception. Boot, using Thymeleaf, will join the starter dependency, the time to introduce this dependency, boot will automatically configure the forwarding rules, so long as you remember in the Pom file declaration of dependency can be

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactid>spring-boot-starter-thymeleaf</artifactid>
</dependency >

Spring will also encounter this situation, the same principle, if you do not declare viewresolver, this problem will occur. I am in the controller, without @responsebody annotations, directly return the "index" string, to map
INDEX.JSP will enter the code above, judging the URI and JSP name are the same, are index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.