我是靠谱客的博主 和谐缘分,最近开发中收集的这篇文章主要介绍spring mvc使用@Controller返回的html视图,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  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


已经很清楚的告诉我们了即使你:

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

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

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

    </bean>

这样配置了

但是你可爱的Web 容器并不知道,你到底要干嘛?解析的是个What.所以你需要在web中注册一下:

<servlet-mapping>

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

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

</servlet-mapping>


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

最后

以上就是和谐缘分为你收集整理的spring mvc使用@Controller返回的html视图的全部内容,希望文章能够帮你解决spring mvc使用@Controller返回的html视图所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部