Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 173
  • Last Modified:

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>
0
ricky06
Asked:
ricky06
2 Solutions
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now