1、前言
在项目中,我们会遇到在线预览,播放MP3、图片、MP4等。用户上传文件后,将路径存储在数据库中,我们可动态读取数据库的数据,然后通过返回文件路径的字符串,在src中发送请求。当然这需要带参数。后台返回流。
2、前台代码:
<script type="text/javascript">
function getVideo(id){
window.location.href="${pageContext.request.contextPath }/Test/getVideo.do?id="+id;
}
</script>
</head>
<body>
<h3>${message }</h3>
<h1>Hello !!!</h1>
<button id="btn" onclick="getVideo('ea48576f30be1669971699c09ad05c94');">播放</button>
<%-- <video id="video" >
<source src="${path }">
</video> --%>
<audio id="mp3" src="${path }" autoplay="true" controls="true">
</audio>
</body>
3、后台代码:
@Controller
@RequestMapping("/Test"