Servlet coding help

G

GoHabsGo

Hi,

I am using IBM's RAD as my IDE. In my servlet, I have coded:

// set the filename for the server side repository ...
serverFileName = "/web/UserSource/" + user + "-" + shortFileName;

// Open up the output file on server ...
FileOutputStream fos = new FileOutputStream(serverFileName);
Writer outf = new OutputStreamWriter(fos,"Cp1047");

The above logic is inside an "if" construct, as I only can set the file
name after some information is retrieved.

Afterwards, outside of this "if", I try to write to the file like so,
(another "if"):

if (cnt > 4 && !prevLine.equals(boundary)) {
outf.write(prevLine);
out.println("<br>" + prevLine);
}

The outf.write(prevLine) statement is flagged as "outf cannot be resolved"

why, since I have previously defined it? How do I correct this error?

Thanks,

Larry
 
R

Rhino

GoHabsGo said:
Hi,

I am using IBM's RAD as my IDE. In my servlet, I have coded:

// set the filename for the server side repository ...
serverFileName = "/web/UserSource/" + user + "-" + shortFileName;

// Open up the output file on server ...
FileOutputStream fos = new FileOutputStream(serverFileName);
Writer outf = new OutputStreamWriter(fos,"Cp1047");

The above logic is inside an "if" construct, as I only can set the file
name after some information is retrieved.

Afterwards, outside of this "if", I try to write to the file like so,
(another "if"):

if (cnt > 4 && !prevLine.equals(boundary)) {
outf.write(prevLine);
out.println("<br>" + prevLine);
}

The outf.write(prevLine) statement is flagged as "outf cannot be resolved"

why, since I have previously defined it? How do I correct this error?

This is a scope issue. You defined 'outf' in one branch of the 'if' so it is
not visible in the 'else' side. Move the definition of 'outf' (and 'fos') to
outside of the 'if' altogether and everything should be fine.
 
G

GoHabsGo

This is a scope issue. You defined 'outf' in one branch of the 'if' so
it is not visible in the 'else' side. Move the definition of 'outf'
(and 'fos') to outside of the 'if' altogether and everything should be
fine.

Thanks Rhino. I can not move the definitions. I defined outf = null
outside of any constructs and that worked.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top