favicon.ico not displaying in spring mvc 3.2.2 per Tomcat 7.0?

十年热恋 提交于 2019-12-10 19:09:07

问题


I'm new to spring mvc and my favicon.ico is not showing up in browser tab using spring 3.2.2 using tomcat 7.0. I have tried looking at related googling but still cannot get it to show up in the browser tab (FF, Chrome, IE...all latest versions to not work) as well as clearing cache and restarting browser.

  • favicon.ico

Located in root of webapp folder (src/main/webapp)

  • index.jsp
<!DOCTYPE html>  
      <html> 
         <head>         
            <link href="favicon.ico" rel="shortcut icon" >
  o o o
  • mvc-dispatcher-server.xml
<context:component-scan base-package="com.website.controllers" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix">
      <value>/WEB-INF/views/</value>
  </property>
  <property name="suffix">
      <value>.jsp</value>
  </property>
</bean>
  • web.xml
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>

回答1:


Make sure the icon is served, i.e. make a request to /favicon.ico and see if it renders.

If it does, add this to your web.xml to make sure Tomcat sends the correct Content-Type with the response:

<mime-mapping>
    <extension>ico</extension>
    <mime-type>image/x-icon</mime-type>
</mime-mapping>

Make sure <mvc:default-servlet-handler /> is present if you map the dispatcher servlet to /.



来源:https://stackoverflow.com/questions/17178658/favicon-ico-not-displaying-in-spring-mvc-3-2-2-per-tomcat-7-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!