title: JSP not working correctly with PrintWriter
body: <p>I currently have two files, register.html and register.jsp. The HTML file asks the user for some information, and the JSP file is supposed to write information to a text file. I keep getting errors with the file, specifically in the <code>PrintWriter</code> portion. Any help would be much appreciated.</p>
  <p>Here is the error I'm getting:</p>
  <pre class="lang-none prettyprint-override"><code>An error occurred at line: 14 in the jsp file: /register.jsp
  Duplicate local variable pw
  11: 
  12: try {   
  13: 
  14:     PrintWriter pw=null;
  15:    pw = new PrintWriter(new FileWriter(new File(nameOfTextFile), true));  
  16:    // PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
  17:     
  </code></pre>
  <p>register.html:</p>
  <pre><code>&lt;%@ page import=&quot;java.io.*, java.util.Date&quot;  %&gt;
  &lt;DOCTYPE! html&gt;
  &lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Registration&lt;/TITLE&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
  &lt;h1&gt;Enter the following information to sign and create an account in the Book.&lt;/h1&gt;
  &lt;form name=registrationForm action=&quot;register.jsp&quot;&gt;
      &lt;table border=0&gt;
          &lt;tr&gt;&lt;td align=right&gt;Username:&lt;/td&gt;
          &lt;td&gt;&lt;input type=text name=&quot;Username&quot; size=25&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td align=right&gt;Password:&lt;/td&gt;
          &lt;td&gt;&lt;input type=text name=&quot;password&quot; size=25&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;&lt;td align=right&gt;Email address:&lt;/td&gt;
          &lt;td&gt;&lt;input type=text name=&quot;email&quot; size=25&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
      &lt;!--&lt;td valign=middle align=right&gt;Comments:&lt;/td&gt;
      &lt;td&gt;&lt;TextArea rows=5 cols=35 name=&quot;comments&quot;&gt;none&lt;/TextArea&gt;
      &lt;/td&gt;--&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Register&quot; name=&quot;button&quot; onClick=&quot;validatingForm()&quot;&gt;
  &lt;input type=reset value=&quot;Start Over&quot;&gt;
  &lt;/form&gt;
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  </code></pre>
  <p>register.jsp:</p>
  <pre><code>&lt;%@ page import=&quot;java.io.* , java.util.Date&quot;  %&gt;
  &lt;HEAD&gt;Thanks for registering!&lt;/TITLE&gt;&lt;/HEAD&gt;
  &lt;BODY&gt;
  &lt;%
  String un =request.getParameter(&quot;Username&quot;);
  String pw =request.getParameter(&quot;password&quot;);
  String nameOfTextFile = &quot;/xampp/tomcat/webapps/gb/userss.txt&quot;; //directory path and name of file
  try {   
  PrintWriter pw=null;
     pw = new PrintWriter(new FileWriter(new File(nameOfTextFile), true));  
     // PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
      pw.println(un);
      pw.println(pw);
      pw.close();
      } catch(IOException e) {
     out.println(e.getMessage());
  }
  %&gt;
  &lt;/BODY&gt;
   &lt;/HTML&gt;
  </code></pre>