i have done the same using a javabean.. the method code is as below.
***************************************
    public String prepareReport() throws Exception{
        java.util.Date  date = new java.util.Date(System.currentTimeMillis());
        String fileName = "file/TrdRep" + userid + (date.getMonth() + 1) + 
date.getDay() + date.getHours() + date.getMinutes() +".csv"; //for the path
        Vector report = new Vector();
        Vector settleResult = new Vector();
        File file = new File("e:/netscape/server4/docs/trade/" + fileName);
        FileWriter fWriter = new FileWriter(file);
        fWriter.write("Trade Search Report \n \n ");
        if (!((settle_type == null) || (settle_type.equals(""))))
        {
            settleResult=getSettleRetrieveResult(); // call the method which populates 
the records.
            if (settleResult.size() > 0){
                trd_time_from = (String)settleResult.elementAt(0);
                trd_time_to = (String)settleResult.elementAt(1);
            }
            else{
                fWriter.write("There is no settlement no in this type of settlement. "
                                + "Search Result is for the default date.");
            }
        }
        report=getRetrieveResult(); // call the method which populates the records.
        if (report.size() > 0){
            fWriter.write("The trade number mentioned here is a composite of the date 
of trade and the trade number assigned by the exchange. The last seven characters of 
the trade number denote the trade number assigned by NSE.");
            fWriter.write("The Search Result for Client Id " + userid);
            fWriter.write("\n TRADE,BUY/SELL,SCRIPT,SERIES,QTY,QTY 
RMNG,PRICE,TIME,CLIENT ID");
            for (int i = 0; i < (report.size()/10); i++) {
                fWriter.write("\n");
                for (int j = 0; j < 10 ; j++){
                                        if(j==4)
                                        continue;
                    fWriter.write(report.elementAt(10*i + j)+ ",");
                }
            }
        }
        fWriter.flush();
        file.deleteOnExit();
        return fileName;
    }
}

***************************************

this method can be written in javabean and called in jsp.

thanks.

------------- Original Message --------------
"Blaney, Colin (CAP, CORP Contractor)" <[EMAIL PROTECTED]> wrote:
To:[EMAIL PROTECTED]
From:"Blaney, Colin (CAP, CORP Contractor)" <[EMAIL PROTECTED]>
Date:Tue, 5 Jun 2001 13:05:20 -0400
Subject:Write to CSV using JSP

        I want to be able to write some web form values to a CSV (or txt) file.  I 
know ho to do this easily in ASP, anyone know the easiest way to do it in JSP?  Here 
is the ASP I
have used.....

        WRITE
        <%
        set FSO = Server.CreateObject("scripting.FileSystemObject")
        set myFile = fso.CreateTextFile("C:\test.txt", true)
        myFile.WriteLine("stuff")
        myFile.WriteLine("more text here")
        myFile.Close
        %>

        READ
        <%
        Const ForReading = 1, ForWriting = 2, ForAppending = 8
        set fso = server.CreateObject("Scripting.FileSystemObject")

        set f = fso.GetFile("C:\test.txt")
        set ts = f.OpenAsTextStream(ForReading, -2)

        TextStreamTest = ts.ReadLine

        Do While not ts.AtEndOfStream
             myText = myText & ts.ReadLine & vbCrLf
                 Response.Write myText
        Loop
        %>

        Thanks,


-----------------------
Colin P. Blaney

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

_____________________________________________________
Chat with your friends as soon as they come online. Get Rediff Bol at
http://bol.rediff.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to