Send to files to client

Hi,
I need to send two separate files using a single HttpResponse. II don't know how to do that, and I'm trying to make a zip file that contains thw two files. The problem is that the two files doesn't exisist on the server, and I don't know how t o put a String Stream into a ZipStream . Some one could help me?
Thanks in advance
Nicola Salvo

I've solved using:
private void extract(OutputStream out){
    PrinterWriter pw = new PrinterWriter(out)
    try{
    finally pw.flush
ZipOutputStream out = new ZipOutputStream(response.getOutputStream());
out.putNextEntry(new ZipEntry("feat.csv");
extract(out)
out.colseEntry();
out.close()Thank for your answer :)

Similar Messages

  • Sending xml file from client to servlet

    Hi,
    I am writing the server component of an applcation, such that it will receive xml files from the clients(standalone application similar to javaSwing stuff but it's coded in C#), and the servlet will have to extract the data from the xml file and update the mySql database. it will also fulfill the client's request for xmlFiles (and extract data from DB, format to xml file and send back to client)
    I'm new to implementing the servlet receiving files from clients so would need some help.
    I've got 3 questions to ask:
    1) How does the servlet receive/returns the xml file from the client as a series of httpPost request/response. Do i send a File or the file's contents as a String to/from the client?
    2) Is it also a must to use socket for the file transfers? I have read in other posts about sockets as well as HttpURLConnection but i don't quite understand.
    3) When I send a file back to the client(client is standalone application written in C# whereas server is coded in java), what do i specify for the HttpResponse.setContentType() in my servlet? (i'm returning the xml file to client)
    Would really appreciate for any help rendered. If you have any useful links, would appreciate them too. Thanks a lot.
    Karen

    I've got 3 questions to ask:
    1) How does the servlet receive/returns the xml file
    from the client as a series of httpPost
    request/response. Do i send a File or the file's
    contents as a String to/from the client?The server will listen on some port for requests. The client has to open a socket to this server to send the file as string to the server.
    see http://java.sun.com/docs/books/tutorial/networking/index.html
    >
    2) Is it also a must to use socket for the file
    transfers? I have read in other posts about sockets as
    well as HttpURLConnection but i don't quite
    understand.You use HttpURLConnection to make a request using the http protocol, instead of opening a socket and then writing the html headers yourself.
    3) When I send a file back to the client(client is
    standalone application written in C# whereas server is
    coded in java), what do i specify for the
    HttpResponse.setContentType() in my servlet? (i'm
    returning the xml file to client)Its up to your receiving program how to interpret this though, so you probably dont need this.

  • With webutil-client_host, send txt file to client printer

    hi,
    I wanna to learn how to send a txt file to client default printer(local or network),
    I created txt file at client disk, and try to send printer directly,
    just try some statement looks like below;
    a.client_host('cmd /c start print C:\TEMP399899.txt /d:lpt1');
    b.client_host('cmd /c start copy C:\TEMP399899.txt lpt1');
    I do not know the command prompt syntax, please help me, reference me,
    thanks

    Hi,
    on a command line type
    print /?
    for the help of how to print documents. On XP this help is
    PRINT [D:device] [[drive:][path]filename[...]]
    /D:device Specifies a print device.
    Frank

  • Sending .mov file to client and can't burn to DVD

    I am sending a proof .mov file to a client that is windows based. Is there any burning software that will burn a .mov file and play on a windows machine without me converting it to a .AVI file? If I do have to convert it to a .AVI file will there be resolution or quality loss and will they even be able to burn that? They have NERO as their burning software, im using toast titanium and have quicktime pro. thanks

    Toast 8 is the answer. Clients want to get something they can play EASY. DVD works on the TV and PC and needs nothing software wise. Worth the money. Plus the video quality looks good enough but really is not good enough to steal and edit.

  • Send a file to client

    Hi!
    I have to send a byte array as a file to the browser. How do I convert byte[] into a resource-type context node, so it can be downloaded?
    Thanks!

    Hi,
    this code does it the other way, but I may be helpfull:
    private byte[] getByteArrayFromResource(IWDResource resource)
    throws FileNotFoundException, IOException {
    InputStream in = resource.read(false);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    int length;
    byte[] part = new byte[10 * 1024];
    while ((length = in.read(part)) != -1) {
    out.write(part, 0, length);
    in.close();
    return out.toByteArray();
    Regards, Bernd

  • Pls help: server send a file upon client's request

    I just started learning Java and I'm trying to write a simple file transfer program. My problem should be in the transfer part. Code as follows:
    Client side:
    package p2pclient;
    import java.io.*;
    import java.net.*;
    public class P2PClient {
    public static void main(String argv[]) throws Exception
      String filename;
      try {
      Socket clientSocket = new Socket("localhost", 6783);
      BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
      filename = inFromUser.readLine();
      DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
      outToServer.writeBytes(filename);
      String newname = "C:\\" + filename;
      File file = new File(newname);
      byte[] Byte = new byte[1120];
      DataInputStream inFromSocket = new DataInputStream(clientSocket.getInputStream());
      FileOutputStream fout = new FileOutputStream(file);
      int reads;
      while((reads = inFromSocket.read(Byte)) != -1){
      fout.write(Byte, 0, Byte.length);
      clientSocket.close();
      catch (java.io.IOException e) {
          System.err.println("error connecting to " + "Daniel-Ding" + ":" + e);
          return;
    }On the server side:
    package p2pserver;
    import java.io.*;
    import java.net.*;
    import java.util.logging.*;
    class FileTransfer implements Runnable {
      private Socket connectionSocket;
      FileTransfer(Socket connectionSocket) {
        this.connectionSocket = connectionSocket;
      public void run(){
            try {
                String fileName;
                BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
                fileName = inFromClient.readLine();
                System.out.println("received filename: "+ fileName);
                File fl = new File(fileName);
                byte[] filebuffer = new byte[1120];
                FileInputStream fin = new FileInputStream(fl);
                int bytesRead;
            while ((bytesRead = fin.read(filebuffer)) != -1) {
                connectionSocket.getOutputStream().write(filebuffer, 0, bytesRead);         
                connectionSocket.close();
            } catch (IOException ex) {
                Logger.getLogger(FileTransfer.class.getName()).log(Level.SEVERE, null, ex);
    class P2PServer {
        public static void main(String argv[]) throws Exception
            ServerSocket welcomeSocket = new ServerSocket(6783);
            while(true) {
                Socket connectionSocket = welcomeSocket.accept();
                FileTransfer ft;
                ft = new FileTransfer(connectionSocket);
                Thread thread = new Thread(ft);
                thread.start();
    }I can see an empty file with the name of 'newname' in my C drive but no data transfered.
    Thanks a lot in advance.

    Hi Peter,
    Sorry to bother you again. I tried to increase the size of the buffer. The speed improved but the transfered file quality became intolerable. I tested it with some mp3 files and found that with large buffer size there was a lot of noise in the transfered mp3s. Any idea what I can do to optimize this trade-off?
    Many thanks.
    Best,
    Daniel

  • Help :- Send Large File From Server To Client

    Hey guys, I am stuck with a problem.Hope u guys might be able to help me out. My problem is :-
    From client i am doing an operation which results in calculation of results by server and saving a file on the server..But i want to see what results have been computed by the server and hence i want to stream that file back to the client..
    The file may be of 100MB as well , that is, the size of the file may be huge.
    I want u guys to tell me how to stream that file back to the client..I tried returning byte array which gets serialized and then received at client side but as i said the file may be huge so memory problem may arise, so returning byte[] from function is not a good solution..
    I am looking something where server can send the file back to the client in chunks..Client keeps receiving these chucks and keep putting them in the file.
    So how to make server send file in chunks??Also, i don't know the hostname and ports...so sockets i can't use...
    Any Another way to do it...??
    is PipedStream a solution??
    Please guys, help me
    Thanks in advance
    Edited by: 854509 on Apr 25, 2011 8:28 AM
    Edited by: 854509 on Apr 25, 2011 8:59 AM

    854509 wrote:
    I knew about sockets but as i said i am able to send request to server by client by calling a remote method...There i haven't used sockets...RMI uses sockets, I assume you mean you don't access to the underlying socket.
    So i wanted to know if we can without using sockets send file back to Client..I would have the RMI return the connection details where the result can be obtains, .e.g with hostname, port, and file name to use.
    I would suggest trying to compress the stream as well (just wrapp the stream on the sender/reciever), especially for files over 1 MB.
    Tell me something abt PipedStreams as well..If they are of any use here or not?I don't see how. PipedStreams can be used to share data between threads in the same process.
    If RMI is your only choice you can perform a method which would return alot of data and have seperate methods to download portions of it.
    e.g.
    public int loadBigFile(String filename); // returns the number of portions.
    public byte[] returnPortion(int n);
    int portions = rmi.loadBigFile("my-big-file.xml");
    for(int i=0;i<portions;i++) {
       byte[] bytes = rmi.returnPortion(i);
       // do something with bytes.
    }You can have the server cleanup the file when the last portion is read.

  • Help! I have recently updated LR5 and before doing so I was able to email files to clients! (Very Convenient) Now my problem is I have not been able to get pass this error message reading "failed to send" which gives no further detail about what to do to

    Help! I have recently updated LR5 and before doing so I was able to email files to clients! (Very Convenient) Now my problem is I have not been able to get pass this error message reading "failed to send" which gives no further detail about what to do to rectify the situation. Someone please guide me through this! Thanks in advance!

    Did this ever get resolved, as I am having the same issue.  Trying to learn LR5 AFTER a decade using Aperture.   I was able to set up a validated account but when I try to send an e-mail or photo I get the simple " Failed to Send " message.   Using latest version of Mac OS X.

  • Best way to securely share file/send link to external client

    I'm looking for the best method of securely sharing and/or sending large files (big Keynote documents and videos) to external clients. Basically a YouSendIt-type solution, but hosted and running off of my OS X Server.
    What I'd like to be able to do is generate a secure URL for an individual file that can be emailed to a client. I would prefer not to have them need a username/password, but just be able to click and download from the link. I'd also like that link to expire after a certain amount of time. I'm not positive if this is the best method, and am open to other options suggestions.
    Would love some advice as I've been Googling for quite a while without any solid suggestions or solutions. Thanks!

    Off the top, and I don't know how familiar you are with bash shell or other scripting languages here...
    Cleanup is one or two lines of bash in a +periodic daily+ script. Delete stuff older than a week or such via a bash shell find command and an rm, mayhap. That stuff is easy, if it's just a "blindly nuke stuff older than a week" or similar logic required. (Test that rm logic carefully as it really stinks to accidentally rm too much.)
    Upload is slightly more involved. Probably a droplet or such, invoking Applescript or a bash shell script to generate a GUID (or a random string) and copy the file into the web files directory. [Here's a start|http://putnamhill.net/codeshop/applescript/applescript_bash.html] toward this; that looks like it'll get you to bash, and you can do what you need from there. Drop a file on the droplet, and you get a GUID-based name generated and an sftp certificate-based transfer up to the server, and a dialog box showing you the filename.
    Or you do an upload via a web form that pulls up the file and manipulates it and tosses up a page with the URL for you. That can easily be a cgi page, since this isn't high-volume stuff.
    If this stuff doesn't exist, it's a day or two to code it in bash. And perl or php or python or ruby or such could likely be used here, too.
    In general: be careful with who and what can be uploaded to your server, too. Allowing a random file upload into the server environment is very close to allowing a server breach. Some of the attacks here are clever, too. (qv: "gifar" files).

  • How to send XML files through Business Connector to client URL

    Dear ALL
    I am new to SAP BC. We have setup BC 4.8 and would like to send out a XML file from BC to Client URL. Could someone please guide me.
    Please suggest solutions.
    Thanks
    Ahmed

    Hello Mickael
    Thanks for your reply. No, we do not have PI. This BC will be used for point to point communication with client.
    Scenario:
    R/3 server to send XML files to BC. BC will load these files ( using pub.getfile service), this file is to be parsed using pub.loaddocument service and then sent to client in XML format wrapped with digital signature. As i am new to BC i am unable to parse this file and wrap it with the digital signaature to send it.
    Kindly advise on how best can we perform this action.
    Thanks
    Ahmed

  • Unable to send a file via my email client

    when i try to send a file via email i get the following error message : ' adobe reader could not  connect to e-mail client' - pl help.
    os; win 7 home premium[64-bit]; browser: ie9; e-mail client : hotmail & gmail

    That pretty much means you don't have an email client. This is something like Outlook Express you may have seen.
    Instead, open your email and attach the PDF.

  • How can I create an csv/excel file using pl/sql and then sending that file

    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.

    968776 wrote:
    How can I create an csv/excel file using pl/sql and then sending that file to a clients site using pl/sql?
    I know how to create the csv/excel file but I can't figure out how I would get it to the clients site.You are trying to do it at a wrong place..
    Whay do you want database (pl/sql) code to do these things?
    Anyhow, you may be interested in :
    {message:id=9360007}
    {message:id=9984244}

  • Sending multiple files using one socket

    Hi guys
    I'm working on a simple app that sends multiple files over LAN or I-NET. The problem is that the app run seems to be non-deterministic. I keep getting this error on the client side:
    java.io.UTFDataFormatException: malformed input around byte 5
            at java.io.DataInputStream.readUTF(Unknown Source)
            at java.io.DataInputStream.readUTF(Unknown Source)
            at service.DownloadManager.storeRawStream(DownloadManager.java:116)
            at service.DownloadManager.downloadFiles(DownloadManager.java:47)
            at manager.NetworkTransferClient$1.run(NetworkTransferClient.java:104)The byte position changes every time I run a transfer. The error is caused by this line: String fileName = in.readUTF(); Here's the complete code:
    Client
    private void storeRawStream() {                               
            try {
                FileOutputStream fileOut;                       
                int fileCount = in.readInt();           
                for(int i=0; i<fileCount; i++) { 
                    byte data[] = new byte[BUFFER];
                    String fileName = in.readUTF();               
                    fileOut = new FileOutputStream(new File(upload, fileName)); 
                    long fileLength = in.readLong();                                 
                    for(int j=0; j<fileLength / BUFFER; j++) {
                        int totalCount = 0;
                        while(totalCount < BUFFER) {                       
                            int count = in.read(data, totalCount, BUFFER - totalCount);
                            totalCount += count;                 
                        fileOut.write(data, 0, totalCount);
                        fileOut.flush();
                        bytesRecieved += totalCount;                                  
                    // read the remaining bytes               
                    int count = in.read(data, 0, (int) (fileLength % BUFFER));                                        
                    fileOut.write(data, 0, count);              
                    fileOut.flush();
                    fileOut.close();      
                    transferLog.append("File " + fileName + " recieved successfully.\n");  
            } catch (Exception ex) {
                ex.printStackTrace();
        }Server
    public void sendFiles(File[] files) throws Exception {
            byte data[] = new byte[BUFFER];
            FileInputStream fileInput;                                       
            out.writeInt(files.length);              
            for (int i=0; i<files.length; i++) {   
                // send the file name
                out.writeUTF(files.getName());
    // send the file length
    out.writeLong(files[i].length());
    fileInput = new FileInputStream(files[i]);
    int count;
    while((count = fileInput.read(data, 0, BUFFER)) != -1) {
    out.write(data, 0, count);
    bytesSent += count;
    fileInput.close();
    out.flush();
    Does anybody know where's the problem? Thanx for any reply.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Send the length of each file ahead of each file, with DataOutputStream.writeLong().
    When reading, read that long, then stop reading bytes when you've read exactly that length.

  • JSP to Upload file from client machine to Web Server!

    Hi,
    I want to upload a file from client machine to web server in order to send it as email attachment, How can I do it? After uploading the file the class should give me the path where the file is stored on the web server and the file name in return!
    I know the HTML <file> field but dont know how to copy it on web server, HTML Part will be:
    <FORM ENCTYPE="multipart/form-data"
    method="POST" action="My.jsp">
    <INPUT TYPE="file" NAME="mptest">
    <INPUT TYPE="submit" VALUE="upload">
    </FORM>
    Please help!
    Thanks,
    - Rahul

    You can use cos.jar provided by O'Reilly from http://www.servlets.com/cos/. Take a look at com.oreilly.servlet.multipart.* classes.
    Package is provided with source, classes, documentation and, of course, ready-to-use jar file.
    It is really usefull and - ready!

  • How to upload file from client machine to  server machine?

    i am developing one web application.I have one html file with browse option. client can browse any type of file. what ever file the client will browse it going to be stored in server machine. for storing the file want to use servlet. my html form is of multipart type.
    can any one send me the servlet code? i am using tomcat 5.5 as web server.

    [http://commons.apache.org/fileupload]
    Start reading 'User Guide' and 'Frequently Asked Questions'.
    Good luck :)

Maybe you are looking for

  • IPod touch 5th generation does not recharge

    My new iPod touch 5th generation, using iOS 6.0.1, is just over 1 month old and today it will not recharge anymore. When I plug teh iPod into an outlet to recharge it no longer makes the "connection" sound and the battery icon does not change to the

  • Is it possible to modify the system colour palette?

    I'm trying to remove (or at least minimise the visual impact of) the grey border present when a subVI smaller in size than the main VI (or screen in general) is run. The subVI is run as modal with all dialog borders/buttons turned off. As far as I ca

  • Problem when creating an outputstream by submiting a form

    hi i am new in this forum, am working on a web application deployed on weblogic and apache server. Im trying to create an outputstream from several xsl transformations. I have a JSP which launches xsl transformations (made by a handler) by submiting

  • G580 Keyboard and Boot manager

    Hi, I have only Windows 7 OS on my machine and every time I start my Laptop, 1)Windows boot manager appears asking me to choose Operating system. Is there anyway to avoid boot manager. 2) The key board is not functioning properly. Shorcut keys like W

  • How to make div id properties drop down wider?

    When working with div's you can assign/create a div ID name to them. These are all remembered throught Dreamweaver so you could apply the same div ID to another div having the CSS properties already created quickly applied to this new div. My issue i