通过jsp中的路径从数据库中检索文件 [英] retrieving files from database by their path in jsp

查看:105
本文介绍了通过jsp中的路径从数据库中检索文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过其路径(本地服务器路径)下载文件存储在数据库表中,我已经完成了编码部分来查看html表中的数据库,但我不知道如何超链接表以便从存储在服务器中的ouput文件夹下载文件(任何类型和大小)。
这里是jsp代码:

i want to download a file by its path(local server path) which is stored in a database table ,i have done the coding part to view the database in a html table but i dont have any idea how to hyperlink the table in order to download the file(any type and size) from the ouput folder that is stored in a server. here is the jsp code :

<%@ page import="java.io.*,java.sql.*"%>

<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();  
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306  /ksa","root","root");  
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select id,file_path,file_date from file12 where id like '"+id+"%'"); 
%>
<table cellpadding="15" border="1">
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getString("id")%> </td>
<td><%=rs.getString("file_path")%> </td>
<td><%=rs.getString("file_date")%> </td>
</tr>
<%}%>
</table>

上面的代码将从数据库检索表到html表。

the above code will retrieve the table from database to html table.

推荐答案

如果rs.getString(file_path)返回一个路径是/home/Desktop/output/something.jpeg意味着你无法下载。因为当你点击给定的链接肯定会显示PAGE NOT FOUND(404)例外。

If the rs.getString("file_path") returns a path is /home/Desktop/output/something.jpeg means you cannot download.Because when you click the given link surely it will show PAGE NOT FOUND (404) Exception.

>点击此处下载文件

请注意您的网址如下

http:// localhost:8080 / prjname / home / Desktop / output / something.jpeg

所以在这种情况下我们可以将路径传递到一个servlet,通过这个servlet我们可以下载文件。

So in this situation we can pass the path into one servlet ,through this servlet we can download the file.

这篇关于通过jsp中的路径从数据库中检索文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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