Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring boot中的Multiple index.html_Java_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

Java spring boot中的Multiple index.html

Java spring boot中的Multiple index.html,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我有一个简单的spring启动应用程序,在我的webapp中有两个html。 在我的控制器中,我编写了如下映射: @Controller public class HtmlController { @RequestMapping(value = "/", method = RequestMethod.GET) public String index() { return "index"; } @RequestMapping(value = "/anotherIndex", meth

我有一个简单的spring启动应用程序,在我的webapp中有两个html。

在我的控制器中,我编写了如下映射:

@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";
}
}
此外,我还有财产:

spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html
当我传入浏览器localhost:8080/-时,我会得到我的index.html页面 但当我通过localhost:8080/anotherIndex时,我有一个异常:

javax.servlet.ServletException: Circular view path [/anotherIndex.html]: would dispatch back to the current handler URL [/anotherIndex.html] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
at org.springframework.web.servlet.view.InternalResourceView.prepareForRendering(InternalResourceView.java:205) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:145) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1282) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) [spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]

我的代码怎么了?

主要问题是您没有使用Spring Boot中为web应用程序定义的文件夹结构

你应该

src
   main
       resources
                templates
                         index.html
                         anotherIndex.html
                         anotherFolder
                             index.html
                         ...
然后从你的控制器使用(你有它的权利)


你有多处打字错误?查看异常中的实际路径;您似乎已经安装了Spring安全性,但没有正确处理登录页面。您的URL(localhost:8080/anoterIndex)中有一个输入错误,没有输入h字母=)抱歉,这是一个伪代码。我问了所有的情况:)是的,我知道这种方法。我在另一个项目中也做了类似的工作,其中后缀“/”和前缀“/index.html”。但还有其他解决办法吗?例如,a.html和b.html有相似的js和css,我不想把它们放在其他文件夹中。你可以创建一个与模板相同级别的静态文件夹,在公共css和js中,因为你的html模板引用了这些文件
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
    return "index";
}

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