title: My Download Servlet runs twice
body: <p>I have a gwt web application with a download servlet and I count downloads of every file in my db. When user sends a download request to server, my download servlet runs twice and my download counter counts 2 every time. but the file that user has sent request for it, has been downloaded once. I don't know whay my servlet runs 2 time for 1 request.</p>
  
  <p>my download servlet:</p>
  
  <pre><code>public class DownloadServlet extends HttpServlet {
  
   private static final String UPLOAD_DIRECTORY = "c:\\update\\";
   private Connection con;
  
   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse resp)
           throws ServletException, IOException {
  
       Statement select=null;
       ResultSet result=null;
  
       try{
  
          Class.forName("com.mysql.jdbc.Driver");
          con = DriverManager.getConnection("jdbc:mysql://localhost:3306/laplasdb?useUnicode=true&amp;characterEncoding=UTF-8","gwt","root");
          }catch(Exception ex){
  
          }
       String query = "SELECT * FROM TBL_Drive_Files WHERE id = '"+req.getParameter("fileid")+"'", filename="";
       InputStream filecontent=null;
  
       int filesize=0;
       try {
           select = con.createStatement();
           result = select.executeQuery(query);
           while (result.next()) {
               filename = result.getString(2);
               filesize = result.getInt(4);
               filecontent = result.getBinaryStream(5);
           }
  
           result.close();
  
       } catch(SQLException e) {
       }
  
  
       BufferedOutputStream output = null; 
       try { 
  
           resp.reset(); 
           resp.setContentType("application/octet-stream"); 
           resp.setContentLength(filesize); 
           resp.setHeader("Content-disposition", "attachment; filename=\"" + filename + "\""); 
           output = new BufferedOutputStream(resp.getOutputStream()); 
           for(int data; (data=filecontent.read()) != -1;) { 
               output.write(data); 
           } 
           output.flush(); 
  
           query = "Update TBL_Drive_Files SET count = count + 1 WHERE id = '"+req.getParameter("fileid")+"'";
           try {
              select = con.createStatement();
              select.execute(query);              
  
              select.close();
              con.close();
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
  
       } 
       catch (IOException e) { 
  
           e.printStackTrace(); 
       } 
       finally {
       }
   }     
  </code></pre>
  
  <p>}</p>
  
  <p>and in client side:</p>
  
  <pre><code>Button bd = new Button("Download", new ClickHandler(){
               public void onClick(ClickEvent event){
                  final String link = GWT.getModuleBaseURL() + "download?fileid=3";
  
                  RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,link);
  
                  try {
                       builder.sendRequest(null, new RequestCallback() {
                       public void onError(Request request, Throwable t) {
                          Window.alert("Error bei getExcel");
                      }
                      public void onResponseReceived(Request request,Response response){
                              int statuscode = response.getStatusCode();
                              if(statuscode == 200) {
                                      Window.Location.replace(link);
                        } else if(statuscode == 404) {
                          Window.alert("Service not available.");
                        }
                      }
                     });
                     } catch (RequestException re) {
                         Window.alert(re.toString());
                     }
               }
      });             
      RootPanel.get().add(bd);
  </code></pre>