Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Servlet coding help

Thread view: 
GoHabsGo - 13 Sep 2006 15:47 GMT
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
Rhino - 13 Sep 2006 17:12 GMT
> Hi,
>
[quoted text clipped - 21 lines]
>
> 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.

--
Rhino
GoHabsGo - 13 Sep 2006 17:39 GMT
>> Hi,
>>
[quoted text clipped - 31 lines]
> --
> Rhino

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.