Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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
SpringWeb4配置InternalResourceViewResolver.setSuffix(";.html";)不工作_Spring_Spring Mvc - Fatal编程技术网

SpringWeb4配置InternalResourceViewResolver.setSuffix(";.html";)不工作

SpringWeb4配置InternalResourceViewResolver.setSuffix(";.html";)不工作,spring,spring-mvc,Spring,Spring Mvc,我尝试使用Java注释创建Spring4项目进行配置 我的配置文件: @Configuration @EnableWebMvc @ComponentScan(basePackages="app.controllers") public class WebAppConfig extends WebMvcConfigurerAdapter{ @Bean public ViewResolver getViewResolver(){ InternalResourceVi

我尝试使用Java注释创建Spring4项目进行配置

我的配置文件:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages="app.controllers")
public class WebAppConfig extends WebMvcConfigurerAdapter{

    @Bean
    public ViewResolver getViewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/view/");
        resolver.setSuffix(".jsp"); // Problem if use .html       
        return resolver;
    }
}
控制器

@Controller
public class AppController {

@RequestMapping("/")
public ModelAndView main() {
    ModelAndView mav = new ModelAndView();
    mav.setViewName("index");
    return mav;      
}
...

我不想使用
.jsp
文件,而是
.html
。我试图将代码更改为
resolver.setSuffix(“.html”)但未找到页面错误。控制器使用
.jsp

可以发布
web.xml
、控制器代码和测试时使用的URL吗?我使用基于java的配置,不使用web.xml。我在视图文件夹中有index.jsp和index.html文件。我尝试使用
localhost:8080/myproject/
。控制器已添加到post。请尝试重命名index.html。假设renamedindex.html.Reading
InternalResourceViewResolver
的JavaDoc可能会给您一个提示,说明它为什么不工作:“支持InternalResourceView(即servlet和JSP)的UrlBasedViewResolver的方便子类以及JstlView之类的子类。”。您能发布
web.xml
,您的控制器代码和测试它的URL?我使用基于java的配置,不使用web.xml。我在视图文件夹中有index.jsp和index.html文件。我尝试使用
localhost:8080/myproject/
。控制器已添加到post。请尝试重命名index.html。假设renamedindex.html.Reading
InternalResourceViewResolver
的JavaDoc可能会给您一个提示,说明它为什么不起作用:“支持InternalResourceView(即servlet和JSP)的UrlBasedViewResolver的方便子类以及JstlView等子类。”。