favicon.ico不能在每个Tomcat 7.0的Spring MVC 3.2.2中显示? [英] favicon.ico not displaying in spring mvc 3.2.2 per Tomcat 7.0?

查看:137
本文介绍了favicon.ico不能在每个Tomcat 7.0的Spring MVC 3.2.2中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是spring mvc的新手,而在使用tomcat 7.0的spring 3.2.2中,我的favicon.ico没有出现在浏览器选项卡中.我尝试查看相关的谷歌搜索,但仍然无法在浏览器选项卡(FF,Chrome,IE ...所有最新版本不起作用)中显示它,以及清除缓存并重新启动浏览器.

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

位于webapp文件夹的根目录(src/main/webapp)

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>
        

        推荐答案

        确保已投放图标,即向/favicon.ico请求并查看其是否呈现.

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

        如果确实如此,请将其添加到您的web.xml中,以确保Tomcat发送正确的Content-Type和响应:

        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>
        

        如果将调度程序servlet映射到/,请确保存在<mvc:default-servlet-handler />.

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

        这篇关于favicon.ico不能在每个Tomcat 7.0的Spring MVC 3.2.2中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆