Spring MVC 返回html等自定义后缀名 页面404错误解决

  1. First the DispatcherServlet is invoked by the Servlet Container. html

  2. The DispatcherServlet finds a mapping which maps to the home method of your Controller and the home method returns a view name "HelloWorld" web

  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. spring

  4. Now essentially a call is made to RequestDispatcher.forward("/WEB-INF/views/HelloWorld.html",.... app

  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. jsp

  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 this


已经很清楚的告诉咱们了即便你: url

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> spa

        <property name="prefix" value="/WEB-INF/views/"/> htm

        <property name="suffix" value=".html"/> servlet

    </bean>

这样配置了

可是你可爱的Web 容器并不知道,你到底要干吗?解析的是个What.因此你须要在web中注册一下:

<servlet-mapping>

<servlet-name>jsp</servlet-name>

<url-pattern>*.html</url-pattern>

</servlet-mapping>


顺道说一句JSP不是和html同样的,只是个文件后缀名而已,一句半句也说不清楚,感兴趣的朋友能够翻翻相关资料。

相关文章
相关标签/搜索