0
votes

I was trying to add some HTML files to the spring project that I was working on. Initially, the project was working fine with JSP files.

This is the folder structure that I'm following: /WEB-INF/views/jsp/hello.jsp

Spring web configuration is as follows:

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/views/jsp");
    viewResolver.setSuffix(".jsp");
    return viewResolver;
}

I tried to replace it with HTML as follows:

@Bean
public InternalResourceViewResolver viewResolver() {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/WEB-INF/static/html/");
    viewResolver.setSuffix(".html");
    return viewResolver;
}

And the request mapping is as follows:

@RequestMapping(value = "/", method = RequestMethod.GET)
public String myMethod(ModelMap model) {
    return "index";
}

Everything is working fine as long as the page is a JSP file. When changed to HTML, it'll start giving errors.

This is the log entry:

15-Dec-2016 11:54:57.408 WARNING [http-apr-9999-exec-2] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/WEB-INF/views/html/index.html] in DispatcherServlet with name 'dispatcher'

1
Please read this post. Maybe is helpful for youuser7298715
The code you are showing is launching hello.html, but in log you are displaying index.html. Do you have index.html file in your folder?Rajashekhar
@Rajashekhar I added the working piece of code by mistake. It's actually index.html. I've edited it in the question. Thanks for pointing it out.Anand MP
Have you change index.jsp to index.html?Sanjay
@SanjayPatel Yes, I didAnand MP

1 Answers

0
votes

maybe you need the following code in file dispatcher-servlet.xml

<!-- JSP VIEW RESOLVER -->
<bean id="jspViewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/views/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>