Dear all, I need to log some information only after a user downloads or opens a file.
I am using a servlet for that and the download part works fine. However I need to identify which button was clicked because in case the user clicks [CANCEL] I am not supposed to register any information. I put lots of messages on the code to understand how it works and even if I click [CANCEL] the messages will be printed showing that all commands will be executed no matter which button was clicked. Can someone help me to identify which button was clicked? Thanks Siomara =================== package servlets.comum; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; /** * Definition of class DownloadFile. */ public class DownloadFile extends HttpServlet { private String original_filename = "MYFILE.txt"; private String filename="C:\\ABC.txt"; /** * Processes requests for both HTTP >GET and POST methods. * @param request servlet request * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { File f = new File(filename); int length = 0; ServletOutputStream op = response.getOutputStream(); ServletContext context = getServletConfig().getServletContext(); String mimetype = context.getMimeType( filename ); System.out.println("here 1"); // Set the response and go! response.setContentType( (mimetype != null) ? mimetype : "application/octet-stream" ); response.setContentLength( (int)f.length() ); response.setHeader( "Content-Disposition", "attachment; filename=\"" + original_filename + "\"" ); System.out.println("here 2"); // Stream to the requester. byte[] bbuf = new byte[filename.length()]; DataInputStream in = new DataInputStream(new FileInputStream(f)); while ((in != null) && ((length = in.read(bbuf)) != -1)) { op.write(bbuf,0,length); } System.out.println("here 3"); in.close(); System.out.println("here 4"); op.flush(); System.out.println("here 5"); op.close(); System.out.println("here 6"); } /** * Handles the HTTP GET method. * @param request servlet request * @param response servlet response */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP POST method. * @param request servlet request * @param response servlet response */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. */ public String getServletInfo() { return "Short description"; } } ============================== Results: [Tue Jul 07 10:39:43 BRT 2009] info: postgres: Opened a new connection [Tue Jul 07 10:39:43 BRT 2009] info: postgres: Delivered connection from pool select arquivolicitacao.licitacaoid, arquivolicitacao.arquivoid, arquivo.tipoarquivoid, arquivo.tituloapresentacao, arquivo.nomeinterno, arquivo.localizacaofisica, arquivo.datapublicacaodou, tipoarquivo.descricao from arquivolicitacao, arquivo, tipoarquivo where arquivolicitacao.licitacaoid = 5 and arquivolicitacao.arquivoid = arquivo.arquivoid and arquivo.tipoarquivoid = tipoarquivo.tipoarquivoid order by datapublicacaodou desc here 1 here 2 here 3 here 4 here 5 here 6