title: Passing values from from Servlet to JSP
body: <p>I am attempting to pass certain values from my servlet to the JSP page and add the values which have been passed to the  tag, reading many posts I've got the following code.</p>
  
  <ol>
  <li>Use input tage to select files</li>
  <li>Verify files uploaded</li>
  <li>invoke upload.java to save uploaded files in WEB-INF</li>
  <li>of the uploaded file a selected file is saved as my.txt</li>
  <li>Use buffers to read contents of the file and save them to a variable</li>
  <li>passing this to the JSP page    </li>
  </ol>
  
  <p>upload.java</p>
  
  <p>After uploading the files,</p>
  
  <pre><code>response.setContentType("text/html");
  String LINE = "&lt;br&gt;";
  String filename = "/WEB-INF/my.txt";
  fileTxt = "";
  ServletContext context = getServletContext();
  InputStream is = context.getResourceAsStream(filename);
  if (is != null) {
  InputStreamReader isr = new InputStreamReader(is);
  BufferedReader reader = new BufferedReader(isr);
  PrintWriter writer = response.getWriter();
  String text = "";
  while ((text = reader.readLine()) != null) {
  fileTxt = text + LINE;
  }
  request.setAttribute("File_Text", fileTxt);
  RequestDispatcher rd = request.getRequestDispatcher("mypage.jsp");
  rd.forward(request, response);
  
  }
  </code></pre>
  
  <p>mypage.jsp</p>
  
  <pre><code>&lt;div id="editor"&gt;&lt;/div&gt;
  
  &lt;form method="post" name="myform" action="upload" target="_blank" enctype="multipart/form-data" style="position: absolute; right: -5%; top: 2%;"&gt;
   Left File :     &lt;input type="file" name="dataFile1" id="fileChooser1" /&gt;&lt;br&gt;&lt;br&gt;
   Right File : &lt;input type="file" name="dataFile2" id="fileChooser2" /&gt;&lt;br&gt;&lt;br&gt;
   Config File :&lt;input type="file" name="dataFile3" id="fileChooser3" /&gt;&lt;br&gt;&lt;br&gt;
  &lt;button type="button" onclick="ValidateFile()"&gt;Click to Upload files&lt;/button&gt;
  &lt;/form&gt;
  &lt;script type='text/javascript'&gt;
  
  function ValidateFile()
  {
  var FileName1 = document.getElementById('fileChooser1').value;
  var FileName2 = document.getElementById('fileChooser2').value;
  var FileName3 = document.getElementById('fileChooser3').value;
  
  if(FileName1.length == 0 &amp;&amp; FileName2.length == 0 &amp;&amp; FileName3.length == 0)
  {
      alert("No files have been selected to upload"); 
  }
  
  else
  {
  if(FileName1 == FileName3 ||  FileName2 == FileName3)
      {
          alert("Configuration file should not be same as left or right files. Please check your uploads");
      }
  else
      {
          document.myform.submit();
      }
  
  var filecontent =   ${File_Text};
  var divv = document.getElementById("editor");
  divv.innerHTML = filecontent;
  
  }
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>Now, after doing all this when I click my upload button, it is just not working and the click is not at all being recognized but when I remove the file accessing code the button works fine..</p>
  
  <ol>
  <li>why is this happening? what to do?</li>
  <li>Is this the right way to accessing values of servlet in JSP?</li>
  </ol>
  
  <p>======================================EDIT=======================================</p>
  
  <p>Just to clarify things further,</p>
  
  <ol>
  <li>User uploads a file</li>
  <li>That file is saved as my.txt</li>
  <li>I am opening this file, reading its contents</li>
  <li>adding those contents to my ACE editor in </li>
  </ol>