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>
the above code will retrieve the table from database to html table.
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.
“> click here to download the file
please note your URL it will look like
http://localhost:8080/prjname/home/Desktop/output/something.jpeg
So in this situation we can pass the path into one servlet ,through this servlet we can download the file.