tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From siom...@portosdobrasil.gov.br
Subject RES: Problems downloading files. How to identify the CANCEL butto n?
Date Wed, 08 Jul 2009 14:36:59 GMT
The buttons I see [OPEN], [SAVE] and [CANCEL] are not created and controlled
by me. They belong to the "download manager window" that comes automatically
with a certain command.

The problem I noticed is that by the time this "download manager window"
shows up the entire code on the servlet has been already executed.

The messages bellow that I included are displayed before any click on any of
those buttons.
> here 1
> here 2
> here 3
> here 4
> here 5
> here 6

Any help is welcome. I am looking so hard for a solution but I am not
finding anything on the web.

Siomara

-----Mensagem original-----
De: Martin Gainty [mailto:mgainty@hotmail.com] 
Enviada em: terça-feira, 7 de julho de 2009 19:51
Para: Tomcat Users List
Assunto: RE: Problems downloading files. How to identify the CANCEL button?


at least 2 ways to determine the button selected
1)set a boolean property which is enabled on or off based on executed button
class MyAction extends ActionSupport {
   private boolean submit;
   private boolean clear;
   public void setSubmit(boolean submit) {
      this.submit = submit;
   }
   public void setClear(boolean clear) {
      this.clear = clear;
   }
   public String execute() {
      if (submit) {
         doSubmit();
         return "submitResult";
      }
      if (clear) {
         doClear();
         return "clearResult";
      }
      return super.execute();
   }
}2)check the name of the button as indicated here
class MyAction extends ActionSupport {
   private String buttonName;
   public void setButtonName(String buttonName) {
      this.buttonName = buttonName;
   }
   public String execute() {
      if ("Submit".equals(buttonName)) {
         doSubmit();
         return "submitResult";
      }
      if ("Clear".equals(buttonName)) {
         doClear();
         return "clearResult";
      }
      return super.execute();
   }
}http://cwiki.apache.org/WW/multiple-submit-buttons.html

many other solutions are available from devs
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
dient lediglich dem Austausch von Informationen und entfaltet keine
rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.






> From: siomara@portosdobrasil.gov.br
> To: users@tomcat.apache.org
> Subject: Problems downloading files. How to identify the CANCEL button?
> Date: Tue, 7 Jul 2009 15:09:05 -0300
> 
> 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

_________________________________________________________________
Insert movie times and more without leaving Hotmail®. 
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutori
al_QuickAdd_062009

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message