Urgent, but I haven't points...[How can I write a file on the server side using JSP??]

I need a physical file on my server...the following statement can write within the buffer (I thnik) then display from the buffer.

If JSP cannot write file in the server side, any good suggestion??
I need the *.txt file to plot a generic chart.


String path = request.getRealPath(".");
FileWriter fw = new FileWriter(path + "temp.txt");
BufferedWriter bw = new BufferedWriter(fw);

bw.write("110,120,102,130,25000");
bw.newLine();
bw.write("120,130,120,170,26000");
bw.newLine();
bw.write("130,120,102,130,25000");
bw.newLine();
bw.write("140,130,120,170,26000");
bw.newLine();
bw.write("150,120,102,130,25000");
bw.newLine();
bw.write("160,130,120,170,26000");
bw.newLine();

bw.flush();
bw.close();
fw.close();

FileReader fr = new FileReader(path + "temp.txt");
BufferedReader br = new BufferedReader(fr);
String Line = br.readLine();

while(Line != null){
out.println(Line + "<BR>");
Line = br.readLine();
}

<applet
    code=AStockChart.class
     archive="AStockChart.jar"
    name=cchart
    width=460
    height=400 >
    <param name="file" value="temp.txt"  <----------------This need a physical file on harddisk
     <param name="img" value="backgrnd.gif">
     <param name="nbpoint" value="15">
    <PARAM NAME="FONTNAME" VALUE="Arial">
    <PARAM NAME="FONTSIZE" VALUE="10">
    <PARAM NAME="AP" VALUE="l">
</applet>
ricky06Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cheekycjCommented:
you want to use a local file to plot the data?

CJ
0
cheekycjCommented:
local == client or local == server?

CJ
0
cheekycjCommented:
oh I see what u are trying to do.

you have two options that I can think of.

pass the file as a url path and have the applet read the data by opening a URLConnection

or

use the JSP to read the file and pass in all the data as delimited strings to the applet (then you can adjust your applet to take various pts as params)

If you can't change applet's code.. try to see where it is reading temp.txt from and output the file there.

CJ
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

ricky06Author Commented:
Dear cheekycj,

Thanks for your kindly help, the purpose of my project is:

I've got an applet with completed coding, it need a text file on my server...to plot a stock chart.

Then I need the client browse my server (in JSP) to select some information (such as date) to generate a chart...so I need JSP get the client selected parameter, then WriteFile physically in text format on my server side (harddisk) that can used by the completed applet.

Or any suggestions to complete this task?
0
kausiksarkarCommented:
use this function to store your text file,
<%!
   public void putFile(String data,String name,String filename) throws IOException{
        File f2 = new File("E:/iPlanet/servers/docs/www/datadir/"+filename);
        if(!f2.exists())f2.mkdirs();
        byte [] buf=data.getBytes();
        OutputStream fo=new FileOutputStream(new File("E:/iPlanet/servers/docs/www/datadir/"+filename));
        for(int i=0;i<buf.length;i++){
            fo.write(buf[i]);
        }
    }
%>
0
kausiksarkarCommented:
"E:/iPlanet/servers/docs/www/datadir/"  is complete directory path where you r going to store the file
0
cheekycjCommented:
well once the user has selected the data use the code provided by kausiksarkar to write the file.

Then you need to read the file using java.io.File api and push it to the applet.

CJ
0
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Split points between cheekycj and kausiksarkar

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.