Hi
I have created a simple search form to search a movies database on my page using jsp and mysql, how can I make a download link after results have been extracted in a result page.
Thanks for your nice reply.

Dani AI

Generated

Two common, reliable patterns used when a search result should offer a file download:

  • Store the file location (path or URL) in the database and render a normal hyperlink. This is simplest and scales well for large files if the files live on disk, CDN, or a protected folder served by the webserver.
  • Store the file itself as a BLOB and stream it back through a servlet/JSP endpoint. This keeps files under application control (authorization, logging) but increases DB size and complexity.

A compact example for the path/URL approach (rendered in the search results):

<a href="${row.filepath}">Download</a>

If files must be protected (not publicly reachable), store the path but serve via a servlet so the link points to a controlled endpoint:

<a href="download?fileId=${row.id}">Download</a>

For the BLOB approach, the servlet should set the MIME type and a Content-Disposition header and then stream the binary column to the response. Example skeleton:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    int id = Integer.parseInt(req.getParameter("fileId"));
    // query DB for filename, mime, and data (BLOB)
    resp.setContentType(mime);
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    try (InputStream in = rs.getBinaryStream("data");
         OutputStream out = resp.getOutputStream()) {
        byte[] buf = new byte[8192];
        int len;
        while ((len = in.read(buf)) != -1) out.write(buf, 0, len);
    }
}

Notes and troubleshooting: avoid loading entire BLOBs into memory; set Content-Length if known; sanitize filenames; prefer filesystem/object storage for very large files; protect download URLs with auth checks. This covers the approaches likely used, matches ’s request to share code-level detail, and gives a step-by-step direction. For reference on binary columns and header behavior, see the MySQL BLOB docs and the Content-Disposition header documentation: MySQL BLOB Content-Disposition (MDN).

Recommended Answers

All 3 Replies

I found how to do it myself. Thanks every body.

Would be nice if you can share your findings with others...

hi.. bugmenot,
actually i need to create search function where it can search from database and display it but unf0rtunately, i still cannot manage to do it.. it seem u already got the result, would u plzz tell me the step or show me how u c0ding it?? thanks a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.