【发布时间】:2015-03-10 13:21:57
【问题描述】:
我正在尝试使用 spring mvc 4 和 apache tomcat 7(在 firefox 中)添加 favicon.ico。 我检查了许多解决方案,但似乎没有一个有效。
web.xml:
<mime-mapping>
<extension>ico</extension>
<mime-type>image/x-icon</mime-type>
</mime-mapping>
mvc-core-config.xml:
<mvc:default-servlet-handler/>
<!-- <mvc:resources mapping="/resources/**" location="/resources/css" /> -->
<mvc:resources location="/favicon.ico" mapping="/favicon.ico" />
jsp:
<link href="MYPROJECT/favicon.ico" rel="icon" type="image/x-icon">
(我也尝试过不使用 MYPROJECT 和其他变体...)。
我将 favicon.ico 文件放在 webapps 下(也在其他文件夹中尝试过)。
加载页面时,不显示图标。
注意:我尝试直接加载图标http://localhost:8080/MYPROJECT/favicon.ico,但收到以下错误消息:the image 'http://localhost:8080/MYPROJECT/favicon.ico' cannot be displayed because it contains errors。我下载了其他 favicon.ico,但图标看起来已损坏。
在 Firefox 中检查元素时,我不会调用 favicon.ico。
有什么建议吗?
更新: 在我的 Eclipse 控制台中,我看到:
查找路径/的处理程序方法 15:48:05.622 [http-bio-8080-exec-6] 调试 o.s.w.s.m.m.a.RequestMappingHandlerMapping - 没有找到 [/] 的处理程序方法 15:48:05.622 [http-bio-8080-exec-6] 调试 o.s.w.s.m.m.a.RequestMappingHandlerMapping - 查找路径 / 的处理程序方法 15:48:05.623 [http-bio-8080-exec-6] 调试 o.s.w.s.m.m.a.RequestMappingHandlerMapping - 没有找到 [/] 的处理程序方法 15:48:05.623 [http-bio-8080-exec-6] 调试 o.s.w.s.h.SimpleUrlHandlerMapping - 使用处理程序 [org.springframework.web.servlet.mvc.ParameterizableViewController@380baa3a] 和 1 个拦截器将 [/] 映射到 HandlerExecutionChain
更新2 mvc 配置 xml:
<import resource="mvc-view-config.xml"/>
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>
<mvc:annotation-driven conversion-service="conversionService"/>
<context:component-scan base-package="controllers,logic.preprocess"/>
<mvc:view-controller path="/" view-name="index" />
<mvc:default-servlet-handler/>
<mvc:resources location="/favicon.ico" mapping="/favicon.ico" />
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages/messages"/>
</beans>
包含的mvc-view-config.xml:
<bean
class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
<list>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
<property name="contentType" value="text/html;charset=UTF-8"></property>
</bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order" value="1"/> </bean>
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="order" value="2" /> </bean>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="3" />
<property name="alwaysUseFullPath" value="true" />
<property name="mappings">
<props>
<prop key="controllers/TaskController">taskController</prop>
<prop key="controllers/ResultController">resultController</prop>
</props>
</property>
</bean>
更新 3 我将文件放在资源/图像下,它似乎只能在 chrome 上部分工作(没有快捷方式),但不能在 firefox 上工作。
谢谢, 迈克
【问题讨论】:
标签: java spring-mvc favicon