解析模板“索引"时出错,模板可能不存在或可能无法被任何配置的模板解析器访问

编程入门 行业动态 更新时间:2024-10-25 20:22:07
本文介绍了解析模板“索引"时出错,模板可能不存在或可能无法被任何配置的模板解析器访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

以前有人问过这个问题,但我没有解决我的问题,而且我得到了一些奇怪的功能.

This question has been asked before but I did not solve my problem and I getting some weird functionality.

如果我像这样将 index.html 文件放在静态目录中:

If I put my index.html file in the static directory like so:

我的浏览器出现以下错误:

I get the following error in my browser:

在我的控制台中:

[THYMELEAF][http-nio-8080-exec-3] Exception processing template "login": Exception parsing document: template="login", line 6 - column 3 2015-08-11 16:09:07.922 ERROR 5756 --- [nio-8080-exec-3] o.a.c.c.C.[.[.[/]. [dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Exception parsing document: template="login", line 6 - column 3] with root cause org.xml.sax.SAXParseException: The element type "meta" must be terminated by the matching end-tag "</meta>".

但是,如果我将 index.html 文件移动到模板目录中,我的浏览器会出现以下错误:

However if I move my index.html file into the templates directory I get the following error in my browser:

我添加了我的视图解析器:

I have added my view resolvers:

@Controller @EnableWebMvc public class WebController extends WebMvcConfigurerAdapter { @Override public void addViewControllers(ViewControllerRegistry registry) { registry.addViewController("/index").setViewName("index"); registry.addViewController("/results").setViewName("results"); registry.addViewController("/login").setViewName("login"); registry.addViewController("/form").setViewName("form"); } @RequestMapping(value="/", method = RequestMethod.GET) public String getHomePage(){ return "index"; } @RequestMapping(value="/form", method=RequestMethod.GET) public String showForm(Person person) { return "form"; } @RequestMapping(value="/form", method=RequestMethod.POST) public String checkPersonInfo(@Valid Person person, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return "form"; } return "redirect:/results"; } @Bean public ViewResolver getViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("templates/"); //resolver.setSuffix(".html"); return resolver; } @Override public void configureDefaultServletHandling( DefaultServletHandlerConfigurer configurer) { configurer.enable(); } }

WebSecurityConfig.java

WebSecurityConfig.java

@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/index").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .permitAll() .and() .logout() .permitAll(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user").password("password").roles("USER"); } }

index.html

<!DOCTYPE html> <html lang="en" xmlns:th="www.w3/1999/xhtml"> <meta> <meta> charset="UTF-8"> <title></title> </head> <body> <h1>Welcome</h1> <a href="../../login.html"><span>Click here to move to the next page</span></a> </body> </html>

此时我不知道发生了什么.谁能给我一些建议?

At this point I do not know what is going on. Can anyone give me some advice?

我在 index.html 中遗漏了一个错字,但我仍然遇到相同的错误

I missed a typo in index.html, but I am still getting the same errors

<!DOCTYPE html> <html lang="en" xmlns:th="www.w3/1999/xhtml"> <head> <meta> charset="UTF-8"> <title></title> </head> <body> <h1>Welcome</h1> <a href="../../login.html"><span>Click here to move to the next page</span></a> </body> </html>

推荐答案

在控制台告诉你是登录冲突.我认为你也应该在 index.html Thymeleaf 中声明.类似的东西:

In the console is telling you that is a conflict with login. I think that you should declare also in the index.html Thymeleaf. Something like:

<html xmlns="www.w3/1999/xhtml" xmlns:th="www.thymeleaf" xmlns:sec="www.thymeleaf/thymeleaf-extras-springsecurity3" xmlns:layout="www.ultraq.nz/thymeleaf/layout"> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>k</title> </head>

更多推荐

解析模板“索引"时出错,模板可能不存在或可能无法被任何配置的模板解析器访问

本文发布于:2023-08-04 03:22:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1292423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模板   不存在   索引   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!