0

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'

6
  • Please read this post. Maybe is helpful for you Commented Dec 15, 2016 at 7:01
  • 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? Commented Dec 15, 2016 at 7:05
  • @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. Commented Dec 15, 2016 at 7:10
  • Have you change index.jsp to index.html? Commented Dec 15, 2016 at 8:24
  • @SanjayPatel Yes, I did Commented Dec 15, 2016 at 9:38

1 Answer 1

0

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.