java - Multiple index.html in spring boot -
i have simple spring boot application 2 html inside webapp.
in controller have written mapping like:
@controller public class htmlcontroller { @requestmapping(value = "/", method = requestmethod.get) public string index() { return "index"; } @requestmapping(value = "/anotherindex", method = requestmethod.get) public string anotherindex() { return "anotherindex"; } }
also have properties:
spring.mvc.view.prefix=/ spring.mvc.view.suffix=.html
when pass in browser localhost:8080/ - index.html page when pass localhost:8080/anotherindex have exception:
javax.servlet.servletexception: circular view path [/anotherindex.html]: dispatch current handler url [/anotherindex.html] again. check viewresolver setup! (hint: may result of unspecified view, due default view name generation.) @ org.springframework.web.servlet.view.internalresourceview.prepareforrendering(internalresourceview.java:205) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.view.internalresourceview.rendermergedoutputmodel(internalresourceview.java:145) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.view.abstractview.render(abstractview.java:303) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.dispatcherservlet.render(dispatcherservlet.java:1282) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.dispatcherservlet.processdispatchresult(dispatcherservlet.java:1037) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:980) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:897) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:970) [spring-webmvc-4.3.7.release.jar:4.3.7.release] @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:861) [spring-webmvc-4.3.7.release.jar:4.3.7.release]
what's wrong code?
the main problem not using folder structure defined web application in spring boot.
you should have
src main resources templates index.html anotherindex.html anotherfolder index.html ...
then controller use (you have right)
@requestmapping(value = "/", method = requestmethod.get) public string index() { return "index"; } @requestmapping(value = "/anotherindex", method = requestmethod.get) public string anotherindex() { return "anotherindex"; }
Comments
Post a Comment