2

Have a sample app and created a

view/HelloWorld.html

page. From my controller, I return the following

public String home(Locale locale, Model model) {
    return "HelloWorld";
}

In debug mode I get this warning/error:

WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/HelloWorld/WEB-INF/views/HelloWorld.html] in DispatcherServlet with name 'appServlet'

contents of my src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".html" />
</beans:bean>

If I rename the .html to .jsp and change above to .jsp then things work fine.

user1361914
  • 411
  • 1
  • 14
  • 26

2 Answers2

11

The flow that the servlet container goes through for this request is the following:

  1. First the DispatcherServlet is invoked by the Servlet Container.
  2. The DispatcherServlet finds a mapping which maps to the home method of your Controller and the home method returns a view name "HelloWorld"
  3. Now the DispatcherServlet uses a View Resolver (your InternalResourceViewResolver) to find the View to render the model through, since the name is "HelloWorld", this maps to the /WEB-INF/view/HelloWorld.html view.
  4. Now essentially a call is made to RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html",....
  5. The Servlet container at this point tries to find the servlet which can handle /WEB-INF/views/HellowWorld.html uri - if it had been a .jsp there is a JSPServlet registered which can handle rendering the jsp, however for *.html there is no servlet registered, so the call ends up with the "default servlet", which is registered with a servlet-mapping of / which probably your DispatcherServlet is.
  6. Now the Dispatcher servlet does not find a controller to handle request for /WEB-INF/views/HelloWorld.html and hence the message that you are seeing

If you want this kind of a extension to be handled by the servlet container, say tomcat, you can register *.html extension to be handled by JSPServlet and then it should work cleanly. Or return forward:/resources/HelloWorld.html which will be considered a static file relative to your resources folder.

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
0

There's a lot of difference between html and jsp. Java server pages are compiled into Java ‘servlets’. It may call beans and enterprise beans, such as Java Beans components and Enterprise Java Beans components, to execute processing on the server. So, having such JSP technology could be a key component in high-level architecture for web-based applications.

Raunak Agarwal
  • 7,117
  • 6
  • 38
  • 62