乐橙视频播放需要插件,所以如果没有插件为了让用户直接下载插件!
首先给个下载链接( • ̀ω•́ )✧
<a href ="controller的路径?filename=LCOpenSDKPlugIn.exe【你的exe文件名】>点此下载</a>
然后是controller٩(๑❛ᴗ❛๑)۶
@RequestMapping("你的名字")
public void download(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setCharacterEncoding("UTF-8");
//设置ContentType字段值
response.setContentType("text/html;charset=utf-8");
//获取所要下载的文件名称
String filename = request.getParameter("filename");
//************下载文件所在目录 路径始终不对后来获取Web项目的全路径
String folder = request.getServletContext().getRealPath("/")+"statics/plug-in/IE/";
//通知浏览器以下载的方式打开
response.addHeader("Content-type", "appllication/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename="+filename);
//通知文件流读取文件
InputStream inputStream = new FileInputStream(folder+filename);
System.out.println(folder+filename);
//获取response对象的输出流
OutputStream out = response.getOutputStream();
byte[] buffer = new byte[1024];
int count = 0;
//循环取出流中的数据
while ((count = inputStream.read(buffer)) != -1) {
out.write(buffer, 0, count);
}
out.close();
out.flush();
}