?
Solved

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

Posted on 2003-04-01
9
Medium Priority
?
172 Views
Last Modified: 2010-04-01
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>
0
Comment
Question by:ricky06
[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
9 Comments
 
LVL 19

Expert Comment

by:cheekycj
ID: 8247433
you want to use a local file to plot the data?

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8247436
local == client or local == server?

CJ
0
 
LVL 19

Accepted Solution

by:
cheekycj earned 152 total points
ID: 8247466
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:ricky06
ID: 8251644
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
 

Assisted Solution

by:kausiksarkar
kausiksarkar earned 148 total points
ID: 8252470
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
 

Expert Comment

by:kausiksarkar
ID: 8252474
"E:/iPlanet/servers/docs/www/datadir/"  is complete directory path where you r going to store the file
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8334164
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
 
LVL 35

Expert Comment

by:girionis
ID: 10078572
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

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
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…

765 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