WEB项目中如何实现禁止下载文件(一)
2012-03-22 18:40
771 查看
前言:该WEB项目为Struts2(struts也可以)
实际背景:在视频点播网站或者其他资源观看及下载网站,要实现限制非法下载。
视频播放:
<object type="application/x-shockwave-flash" data="http://localhost:8080/video/flv/vcastr3.swf" width="555" height="430" id="vcastr3">
<param name="movie" value="http://localhost:8080/video/flv/vcastr3.swf" />
<param name="allowFullScreen" value="true" />
<param name="FlashVars" value="xml=<vcastr>
<plugIns>
<javaScriptPlugIn>
<url>http://localhost:8080/video/flv/javaScriptPlugIn.swf</url>
</javaScriptPlugIn>
</plugIns>
<channel>
<item>
<source>1.flv</source>
</item>
</channel>
</vcastr>" />
</object>
只要你知道对方的网址及看到这段页面源码,可以使用任意下载工具(如迅雷),建立任务就能下载
步骤一:在该项目的的WEB.xml下添加
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.flv</url-pattern>
</filter-mapping>
这样在播放页面是无法播放了 因为struts将flv作为请求拦截住了,但是找不到这个Action(但是迅雷还能下载,囧)
步骤二:
jsp:
......
<item>
<source>download.flv?id=1</source>
</item>
......
struts.xml中:
<action name="download" class="com.download.action.DownloadAction">
<result name="success" type="stream">
<param name="contentType">flv-application/octet-stream</param>
<param name="contentDisposition">file="1.flv"</param>
<param name="inputName">DownloadFile</param>
</result>
<interceptor-ref name="defaultStack" />
</action>
DownloadAction
......
public class DownloadAction extends _ExtendsAction {
private Integer id;
public Integer getid() {
return videoId;
}
public void setid(Integer Id) {
this.videoId = videoId;
}
public InputStream getDownloadFile()
{
HttpServletRequest request = ServletActionContext.getRequest();
User user = (User)request.getSession().getAttribute("User");
if(user == null)
return ServletActionContext.getServletContext().getResourceAsStream("/video
/flv/"+"请不要非法下载.flv");
else
return ServletActionContext.getServletContext().getResourceAsStream("/video
/flv/"+id+".flv");
}
public String execute() throws Exception
{
return "success";
}
......
到这里位置我们就实现了禁止文件下载的功能(迅雷下载只能下载到“请不要非法下载.flv”因为没有session)
实现原理:将文件(flv,rar)等资源文件的后缀名成为struts2的Action后缀,然后使用struts2的文件下载功能,这样我们就可以经过一系列的控制阻止非法的下载。
缺点:只能针对指定的资源文件进行拦截,如有不同资源软件,均要进行方法设置
WEB项目中如何实现禁止下载文件(二)
http://blog.csdn.net/linshaoxu123/article/details/7384350
如何获取本地缓存的视频
复制下面代码至txt文件并重命名为bat文件,可以读取IE缓存所有东西
echo off
cls
echo 请选择要提取的文件类型
echo 1(swf) 2(flv) 3(jpg) 4(gif) 5(mp3) 6(mid) 7(其它类型)
set /p type=
if %type%==1 (set filetype=swf)
if %type%==2 (set filetype=flv)
if %type%==3 (set filetype=jpg)
if %type%==4 (set filetype=gif)
if %type%==5 (set filetype=mp3)
if %type%==6 (set filetype=mid)
if %type%==7 (echo 请输入文件类型,例如bmp
set /p filetype=)
for /f "tokens=1,2*" %%i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"^|find /i "Cache"') do set "IEtmp=%%k"
::echo %userprofile%%IEtmp:~13% 从注册表里提取的缓存目录
:select_del_or_not
echo 提取后是否删除原文件?(y/n)
set /p delornot=
if %delornot%==y (goto startcopy)
if %delornot%==n (goto startcopy)
goto select_del_or_not
:startcopy
echo 正在提取文件,请稍候……
md %filetype%
for /f "delims=" %%i in ('dir "%userprofile%%IEtmp:~13%\*.%filetype%" /s/b') do copy /y "%%i" "%CD%\%filetype%\"
if %delornot%==y (for /f "delims=" %%i in ('dir "%userprofile%%IEtmp:~13%\*.%filetype%" /s/b') do del /f/q "%%i")
pause
goto startcopy
但是使用先前的拦截方法,提取文件都被重名名掉了,只有download.flv这个文件,除非你看一次再提取一次
实际背景:在视频点播网站或者其他资源观看及下载网站,要实现限制非法下载。
视频播放:
<object type="application/x-shockwave-flash" data="http://localhost:8080/video/flv/vcastr3.swf" width="555" height="430" id="vcastr3">
<param name="movie" value="http://localhost:8080/video/flv/vcastr3.swf" />
<param name="allowFullScreen" value="true" />
<param name="FlashVars" value="xml=<vcastr>
<plugIns>
<javaScriptPlugIn>
<url>http://localhost:8080/video/flv/javaScriptPlugIn.swf</url>
</javaScriptPlugIn>
</plugIns>
<channel>
<item>
<source>1.flv</source>
</item>
</channel>
</vcastr>" />
</object>
只要你知道对方的网址及看到这段页面源码,可以使用任意下载工具(如迅雷),建立任务就能下载
步骤一:在该项目的的WEB.xml下添加
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>*.flv</url-pattern>
</filter-mapping>
这样在播放页面是无法播放了 因为struts将flv作为请求拦截住了,但是找不到这个Action(但是迅雷还能下载,囧)
步骤二:
jsp:
......
<item>
<source>download.flv?id=1</source>
</item>
......
struts.xml中:
<action name="download" class="com.download.action.DownloadAction">
<result name="success" type="stream">
<param name="contentType">flv-application/octet-stream</param>
<param name="contentDisposition">file="1.flv"</param>
<param name="inputName">DownloadFile</param>
</result>
<interceptor-ref name="defaultStack" />
</action>
DownloadAction
......
public class DownloadAction extends _ExtendsAction {
private Integer id;
public Integer getid() {
return videoId;
}
public void setid(Integer Id) {
this.videoId = videoId;
}
public InputStream getDownloadFile()
{
HttpServletRequest request = ServletActionContext.getRequest();
User user = (User)request.getSession().getAttribute("User");
if(user == null)
return ServletActionContext.getServletContext().getResourceAsStream("/video
/flv/"+"请不要非法下载.flv");
else
return ServletActionContext.getServletContext().getResourceAsStream("/video
/flv/"+id+".flv");
}
public String execute() throws Exception
{
return "success";
}
......
到这里位置我们就实现了禁止文件下载的功能(迅雷下载只能下载到“请不要非法下载.flv”因为没有session)
实现原理:将文件(flv,rar)等资源文件的后缀名成为struts2的Action后缀,然后使用struts2的文件下载功能,这样我们就可以经过一系列的控制阻止非法的下载。
缺点:只能针对指定的资源文件进行拦截,如有不同资源软件,均要进行方法设置
WEB项目中如何实现禁止下载文件(二)
http://blog.csdn.net/linshaoxu123/article/details/7384350如何获取本地缓存的视频
复制下面代码至txt文件并重命名为bat文件,可以读取IE缓存所有东西
echo off
cls
echo 请选择要提取的文件类型
echo 1(swf) 2(flv) 3(jpg) 4(gif) 5(mp3) 6(mid) 7(其它类型)
set /p type=
if %type%==1 (set filetype=swf)
if %type%==2 (set filetype=flv)
if %type%==3 (set filetype=jpg)
if %type%==4 (set filetype=gif)
if %type%==5 (set filetype=mp3)
if %type%==6 (set filetype=mid)
if %type%==7 (echo 请输入文件类型,例如bmp
set /p filetype=)
for /f "tokens=1,2*" %%i in ('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"^|find /i "Cache"') do set "IEtmp=%%k"
::echo %userprofile%%IEtmp:~13% 从注册表里提取的缓存目录
:select_del_or_not
echo 提取后是否删除原文件?(y/n)
set /p delornot=
if %delornot%==y (goto startcopy)
if %delornot%==n (goto startcopy)
goto select_del_or_not
:startcopy
echo 正在提取文件,请稍候……
md %filetype%
for /f "delims=" %%i in ('dir "%userprofile%%IEtmp:~13%\*.%filetype%" /s/b') do copy /y "%%i" "%CD%\%filetype%\"
if %delornot%==y (for /f "delims=" %%i in ('dir "%userprofile%%IEtmp:~13%\*.%filetype%" /s/b') do del /f/q "%%i")
pause
goto startcopy
但是使用先前的拦截方法,提取文件都被重名名掉了,只有download.flv这个文件,除非你看一次再提取一次
相关文章推荐
- WEB项目中如何实现禁止下载文件(二)
- Java - 如何在基于Java的Web项目中实现文件上传和下载?
- Java web项目实现文件下载...【Pnoker】
- 如何在我自己的web 项目的jsp页面中添加链接,直接让别人通过内网在我的电脑上下载文件
- 在java的WEB项目如何防止浏览器直接打开下载的文件
- 如何实现web应用下载文件时不弹出文件保存对话框,而是直接保存到指定的文件中
- web服务器如何判断客户端文件已下载结束?(php实现)
- 如何实现把web项目的输出流重置,并将打印语句结果写到日志文件
- Web项目中使用java Struts2实现Zip、xml文件的动态创建和下载(Zip文件中动态存在多个xml文件)
- 论前后台如何实现web中文件下载功能
- Django 如何实现文件下载
- Android中如何实现文件下载
- Android中如何实现文件下载
- JQuery 中 AJAX 如何实现 Excel 文件 下载
- @如何脚本实现ftp文件下载?@
- 在一个Android项目里面有两个可运行文件,如何实现调用方式
- 关于JAVA EE项目在WEB-INF目录下的jsp页面如何访问WebRoot中的CSS和JS文件
- Android使用开源项目Xutils实现多线程下载文件
- tomcat部署web项目后无法下载工程下某个目录中的文件
- WebView中实现文件下载功能