Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7774871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:29:15+00:00 2026-06-01T17:29:15+00:00

I currently have two files, register.html and register.jsp. The HTML file asks the user

  • 0

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 PrintWriter portion. Any help would be much appreciated.

Here is the error I’m getting:

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:     

register.html:

<%@ page import="java.io.*, java.util.Date"  %>
<DOCTYPE! html>
<HTML>
<HEAD>
<TITLE>Registration</TITLE>
</HEAD>
<BODY>
<h1>Enter the following information to sign and create an account in the Book.</h1>
<form name=registrationForm action="register.jsp">
    <table border=0>
        <tr><td align=right>Username:</td>
        <td><input type=text name="Username" size=25></td>
    </tr>
    <tr><td align=right>Password:</td>
        <td><input type=text name="password" size=25></td>
    </tr>
    <tr><td align=right>Email address:</td>
        <td><input type=text name="email" size=25></td>
    </tr>
    <tr>
    <!--<td valign=middle align=right>Comments:</td>
    <td><TextArea rows=5 cols=35 name="comments">none</TextArea>
    </td>-->
    </tr>
</table>
<br>
<input type="submit" value="Register" name="button" onClick="validatingForm()">
<input type=reset value="Start Over">
</form>
</BODY>
</HTML>

register.jsp:

<%@ page import="java.io.* , java.util.Date"  %>
<HEAD>Thanks for registering!</TITLE></HEAD>
<BODY>
<%
String un =request.getParameter("Username");
String pw =request.getParameter("password");
String nameOfTextFile = "/xampp/tomcat/webapps/gb/userss.txt"; //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());
}
%>
</BODY>
 </HTML>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:29:16+00:00Added an answer on June 1, 2026 at 5:29 pm

    As others have said you should move this code into a java class. With that being said I believe your issue is that you have defined two variables named pw.

    String un =request.getParameter("Username");
    String pw =request.getParameter("password"); //FIRST DECLARATION OF PW
    String nameOfTextFile = "/xampp/tomcat/webapps/gb/userss.txt"; //directory path and name of file
    try {   
    PrintWriter pw=null; //SECOND DECLARATION OF PW causes error
       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());
    }
    

    Try:

    String un =request.getParameter("Username");
    String pw =request.getParameter("password");
    String nameOfTextFile = "/xampp/tomcat/webapps/gb/userss.txt"; //directory path and name of file
    try {   
    PrintWriter printWriter=null;
       printWriter = new PrintWriter(new FileWriter(new File(nameOfTextFile), true));  
       // PrintWriter pw = new PrintWriter(new FileOutputStream(nameOfTextFile));
        printWriter.println(un);
        printWriter.println(pw);
        printWriter.close();
        } catch(IOException e) {
       out.println(e.getMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including
I currently have two arrays one the stores a file name and another that
currently, I am struggeling with the following: I have two Excel files. One files
I have two programs one of which writes some entries into a file and
I currently have two panels within another large panel. The left panel is for
I (currently) have two forms, one that needs to call the other. In other
I currently have two threads running in my program: Main thread - Grabs image
We currently have two EC2 servers running apache servers with django wsgi on freebsd.
Is it possible to combine Underscore's filter and map? I currently have two separate
Currently I have two pages: The first page contains an input form, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.