在Spring MVC 3.0中允许音频文件? [英] Allowing audio files in Spring MVC 3.0?

查看:191
本文介绍了在Spring MVC 3.0中允许音频文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring MVC 3.0,在这里我指定以下mvc:resources标记以允许静态资源通过:-

I'm using Spring MVC 3.0 where I specify the following mvc:resources tag to allow the static resources through:-

<mvc:resources location="/resources/" mapping="/resources/**" />

不知何故,我无法正常使用音频文件.我决定将图像文件放在相同的位置,只是为了测试路径,并且效果很好.

Somehow, I'm having problem getting my audio files to work. I decided to place an image file in the same location just to test the path and that works fine.

http://server/context/resources/test/image.jpg -> works fine
http://server/context/resources/test/audio.mp3 -> I get 404 error

我阅读了 Spring MVC文档,并没有真正描述什么是静态资源,我认为mp3文件是静态资源.

I read the Spring MVC documentation and it doesn't actually describe what's considered as static resources, and I would think the mp3 file is a static resource.

如何使音频文件与Spring MVC 3.0一起使用?谢谢.

How do I get my audio file to work with Spring MVC 3.0? Thanks.

编辑

我的servlet.xml看起来像这样:-

My servlet.xml looks like this:-

<context:component-scan base-package="some.project.controller" />

<mvc:annotation-driven />

<mvc:resources location="/resources/" mapping="/resources/**" />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/app/" />
    <property name="suffix" value=".jsp" />
</bean>

推荐答案

我经常需要为WAS上的静态内容定义此servlet.尝试将其添加为.mp3

I often need to define this servlet for static content on WAS. Try adding it for .mp3

<servlet>
    <servlet-name>static</servlet-name>
    <servlet-class>com.ibm.ws.webcontainer.servlet.SimpleFileServlet</servlet-class>
</servlet>

具有以下映射

<servlet-mapping>
    <servlet-name>static</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>static</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>static</servlet-name>
    <url-pattern>*.mp3</url-pattern>
</servlet-mapping>

这篇关于在Spring MVC 3.0中允许音频文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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