如何在Spring MVC中浏览htm文件
我正在使用 Spring MVC 2 的默认配置。因此,我的调度程序看起来像,
<prop key="index.htm">indexController</prop>
我在根目录下有一个简单的 htm 文件。当我浏览此文件时,出现 404:Not Found 错误。如何在 Spring MVC 中浏览(物理存在于磁盘上)htm 文件。
I am using default configuration of Spring MVC 2. So, my dispatcher will look like,
<prop key="index.htm">indexController</prop>
I have a simple htm file on root. When I browse this file I get 404:Not Found Error. How to browse (which exist physically on disk) htm file in Spring MVC.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在基于注释的 Spring 3.x 中,您可以将其写在控制器中,
如果您以“/pathToIt/index.htm”形式发出请求,那么它将被 doSomeJob() 方法捕获。
PS 不需要Spring MVC 3.x 中配置文件中的请求映射
注意:如果 spring 找不到您的物理文件,也可能导致 404。
In annotation based Spring 3.x, you can just write it in your controller as,
and if you make a request as "/pathToIt/index.htm", then it will be caught by doSomeJob() method..
P.S No need for request mappings in configuration files in Spring MVC 3.x
Note: And also 404 can be caused if spring can't find your physical file..
尝试在 springmvc-servlet.xml 文件中添加一个 bean id:
然后:
Try and add a bean id in your springmvc-servlet.xml file :
then :
好吧,这听起来很熟悉,如果您使用的是 MVC 2,那么实现此目的的最佳方法是为调度程序 servlet 提供特定的映射,而不是 /
Ok this sounds familiar , if you are using MVC 2 then the best way to achieve this is to give a specific mapping for dispatcher servlet instead of /
您需要将 URL
index.htm
与您的控制器进行映射。在页面具有正确的 spring mvc 配置之前,您无法查看页面。在控制器中,您将在
modelAndView
中将 jsp 页面名称作为view
传递。检查您的视图解析器是否有正确的设置,如下所示
You need to map URL
index.htm
with your controller. You cannot view your page until it will have correct spring mvc configuration.In controller you will pass your jsp page name as
view
inmodelAndView
.Check your view resolver has correct setting like this