Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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/5/sql/72.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
Spring引导(使用tomcat)url重定向无模板引擎_Tomcat_Spring Boot - Fatal编程技术网

Spring引导(使用tomcat)url重定向无模板引擎

Spring引导(使用tomcat)url重定向无模板引擎,tomcat,spring-boot,Tomcat,Spring Boot,我正在为我的web服务和web应用程序使用Spring Boot。现在我不想让我的web服务器自动从www.mypage.com:8080重定向到www.mapage.com:8080/index.html 我不想使用任何像Thymeleaf这样的模板引擎,所以我不能通过控制器中的@RequestMapping来实现这一点,因为使用@RequestMapping按方法返回字符串实际上会将该字符串打印为文本,而不是获取文件并呈现它 我还通过添加.addResourceHandler/**.addR

我正在为我的web服务和web应用程序使用Spring Boot。现在我不想让我的web服务器自动从www.mypage.com:8080重定向到www.mapage.com:8080/index.html

我不想使用任何像Thymeleaf这样的模板引擎,所以我不能通过控制器中的@RequestMapping来实现这一点,因为使用@RequestMapping按方法返回字符串实际上会将该字符串打印为文本,而不是获取文件并呈现它

我还通过添加.addResourceHandler/**.addResourceLocations/,classpath:/templates/,使根url+后缀ex.www.mypage.com:8080/page2.html使用resources/templates目录作为源。在此之后,手动输入www.mypage.com:8080/index.html或www.mypage.com:8080/page2.html将显示正确的页面

所以我想问的是,有没有一种方法可以将www.mypage.com映射到mypage.com/index.html,并且仍然可以使用其他页面,比如www.mypage.com:8080/page2.html,也就是root page/来查看参考资料/模板目录?
也许重定向或其他东西会有助于在spring boot中使用tomcat 7?

您不使用模板引擎,所以我假设您的HTML文件是静态文件。为了实现您的目标,将HTML文件放入目录src/main/resources/static/。在您的情况下,将index.html文件放到这个文件夹中,只需调用http:///index.html.

要从http:///重新定向到此文件,请按如下方式创建控制器:

@控制器 公共类家庭控制器{ @请求映射值=/ 公共字符串索引{ 返回重定向:/index.html; } } 无需添加资源处理程序等其他更改。

请执行以下操作:

@Controller
@RequestMapping("/")
public class RedirectController {

    @GetMapping("/forwardWithForwardPrefix")
    public ModelAndView redirectWithUsingForwardPrefix() {
        return new ModelAndView("forward:/redirectedUrl");
    }
}

不为我工作,不知道为什么,但这个重定向不起作用我制作了资源处理程序,因为使用资源/静态不适用于我的js和css在过去我只将它们保持在静态中,所以我映射了静态和模板只是为了完成它我还在这个应用程序中创建了REST服务,所以它们之间可能存在某种冲突-我使用的是spring REST&无论如何,SpringWebMVC感谢您在spring中澄清了它们的工作原理