Whenever you submit a form to download a file the response sent back is a file. In this case the setter called after the method which does the download has no effect.

 if(form.getDownloadForm != null && form.getDownloadForm.equals("Y"))
   downloadForm(form, request);

   //The Below Setter has No Effect
 class RegisterForm()
   public String downloadForm;

    public void setDownloadForm(String p_download) 
	  this.downloadForm= p_download;
    public String getDownloadForm() 
	  return downloadForm;

The Setter had no effect since the request sent to the downloadForm(form, request); will end up with response of file download and not response which has new values to form set by setter(in our case downloadForm(form, request)) and Page reload.

There are 2 simple fix for this.

Fix 1
One simple fix is to set form hidden property in java script to N after the form get submitted. Note though the form is submitted it is not reloaded with new response since the response sent back is a file.

The Page will be reloaded only when response is sent back to the same URL of browser. Not to the browser as file.

 function downloadWFSetup(pWaterfallId) 

    //This part of code runs even after the form submission since the 
    //response sent is file which does not require page reload

In our case the page is not going to get reloaded so the java script continues its execution even after form submission setting property of downloadForm to N.

Fix 2
The Other way is to send request in Link with downloadForm=Y. In this case there is no need to to reset the form values as we get the values by request.getParameter() Method.

The below code reads a Sample.txt file and places the content in a newly created Html file Sample.html.

The file from which the content should be read is placed in a project directory which is printed in the console using the below java code.

System.out.println("Working Directory = " + System.getProperty("user.dir"));

The above code prints the current project directory in console.

package com.mugil.servlets;

import java.awt.Desktop;
import java.io.*;

class GenerateHTML 
    public static void main(String[] args) throws Exception 
    	System.out.println("Working Directory = " +
        BufferedReader br = new BufferedReader(new FileReader("Sample.txt"));
        File f = new File("source.htm");
        BufferedWriter bw = new BufferedWriter(new FileWriter(f));
        bw.write("<h1>ShowGeneratedHtml source</h1>");

        String line;
        while ((line=br.readLine())!=null) {