Hello there,

Im new in JSP
Just want to ask, how I can force web browser to popup download box to download the .prn file that was generated by server?

Assume that


is the variable that hold the path for .prn file

*** Im using pure JSP

skycrew>that was generated by server?

Server prepare a response object - A response object consists headers and body. Headers are instructions for the browser and body contains the data to be render by the browser.

For downloading a file:

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

    void download(String filename,PageContext out) throws Exception {

       ServletContext sc=getServletContext();
       File file=new File(sc.getReadPath("/files");  // assume that your .prn is located under files folder.
       String path="";
       path=sc.getRealPath("files\\" + filename);
       InputStream fr=new FileInputStream(path);
       byte []b=new byte[fr.available()];
        HttpServletResponse resp=(HttpServletResponse)out.getResponse();

       resp.setHeader("Content-Disposition","attachment; filename=" + filename);

// call to a download() method

thank you very much adatapost for the strong explanation and code.

will trying this code.

actually I use the .prn file to print a bar code using bar code printer.

before this, the barcode printer is on client side and the system run locally.

now when the system run on network, client cannot print the barcode because the barcode printer is on client side.

This article has been dead for over six months. Start a new discussion instead.