[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Printing to a file from a jsp on a server.

Posted on 2004-10-25
6
Medium Priority
?
355 Views
Last Modified: 2010-04-01
I want to print stats to a file from a jsp, on the machine that the jsp is running on i.e.

the name of the machine is "test"  the jsp is running on a server on this machine
and i want to create a file on that server under a specific directory i.e


/test/logs/

where test is a root directory.

I also want to be able to append data to this file without it being over written, how
is it possible to do that.

Any help greatly appreciated.
0
Comment
Question by:pronane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 225 total points
ID: 12398506
<%
    java.io.BufferedWriter bw = null ;
    try
    {
        bw = new BufferedWriter( new FileWriter( "/test/logs/log.txt", true ) ) ;
        bw.write( "Hi there at " + new Date().toString() + "\n" ) ;
    }
    catch( java.io.IOException ex )
    {
        ex.printStackTrace() ;
    }
    finally
    {
        try { if( bw != null ) bw.close() ; } catch( java.io.IOException ex ) {}
    }
%>
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12398514
Also, look at the apache.commons.logging libraries (which I think come with tomcat)

http://jakarta.apache.org/commons/logging/guide.html
0
 
LVL 1

Author Comment

by:pronane
ID: 12398631
cheers tim

does the write method append to a file OR WRITE over previous content?

Also what if any given folder on that server isnt world writeable, will the jsp
still be able to create a file under that folder?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:TimYates
ID: 12398670
> new FileWriter( "/test/logs/log.txt", true )

The "true" parameter means it will append to the file :-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12398672
> Also what if any given folder on that server isnt world writeable, will the jsp
> still be able to create a file under that folder?

It depends on the access rights of the tomcat process...

If the user that is considered to be running tomcat has no write access to that folder, it will get an IOException, and not create/append that file...
0
 
LVL 35

Expert Comment

by:TimYates
ID: 12398877
*sniff* only a B grade :-(

Good luck with it...

Tim
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question