Streaming files through a Servlet to macintosh clients

Hi,
I have a servlet which streams diffrent kind of files to the client. I works perfectly with Windows and IE5.0,6.0 and Firefox. But on macintosh (IE5.2) the file name is the name of the servlet. In example if the servlet is named getFile, the file name used by the macintosh client to save the file will be getFile.
Does anyone know the trick to make macintosh clients corretly resolve the filename/mime type??
Thanks

I finally figured out that setting my conent type like this:
response.setContentType("application/octet-stream");
works.
But now I'm stuck with another little problem, Mac does not seem to convert the %20 is filenames to spaces.
Any suggestions?

Similar Messages

  • Streaming files through servlet

    Hi,
    I'm trying to stream a file to the client browser via a Struts action. I use a helper method as follows:
    public static void streamFile(HttpServletResponse response, String contentType, String fileName, InputStream fileData) throws Exception {
              response.setContentType(contentType);
              response.setHeader("Content-disposition", "attachment; filename=" + fileName);
              BufferedInputStream bis = null;
              BufferedOutputStream bos = null;
              OutputStream out = response.getOutputStream();
              try {     
                   bis = new BufferedInputStream(fileData);
                   bos = new BufferedOutputStream(out);
                   byte[] buff = new byte[2048];
                   int bytesRead;
                   //     Simple read/write loop.
                   while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
                        bos.write(buff, 0, bytesRead);
              } catch (Exception e) {
                   throw new Exception("Could not stream file. Error: " + e.getMessage());
              } finally {
                   if (bis != null) {
                        bis.close();
                   if (bos != null) {
                        bos.close();
         }Here's the execute method code for my download action:
    InputStream is = new FileInputStream(new File("g:/Test.txt"));
              FileHelper.streamFile(response, "text/plain", "Test.txt", is);
              return null; "G:\Test.txt" is a valid file. When I tried to run the code, I got this error from the client:
    Internet Exporer cannot download download.do from 127.0.0.1. Internet Explorer was not able to open this site.
    The requested site is either unavailable or cannot be found. Please try again later.
    Any ideas what I'm missing here?
    Thanks in advance for any suggestions!

    Hi all,
    Have found out what's wrong with this.
    Seems like the struts contoller was set to use nocache="true" option, which causes problems because in order for files to be downloaded onto the client, caching must be enabled.
    This applies for all web application processes which need to download files onto the client.
    E.g., if you are using servlets/JSP, you need to make sure that you do not send the pragma=no-cache header.
    E.g. if you use a framework like Struts, you need to make sure that the framework does not disable caching for the module which handles the download.

  • Generating pdf file through jsp/servlet

    One of the MIME types for servlets/JSP response is "application/pdf".
    After setting Content-Type header "application/pdf" in servlet by
    setContentType() method, I am unable to get the output in a pdf file.
    Please let me know how I can generate a pdf file through Servelt/JSP
    response.
    Thanks.

    We've got a product which allows you to convert XML to PDF from a JSP. It doesn't currently take straight HTML, but the XML syntax we use is pretty similar (you can use CSS2 and so on), so for many pages it doesn't take a lot of conversion.
    If you check out http://big.faceless.org/products/report/examples.jsp you'll see a few examples, two of which are dynamically run from a JSP. There's a free trial download for you to test with (although it's a commercial product).
    Hope that helps.
    Cheers... Mike
    Mike Bremford - CTO mike at big.faceless.org
    Big Faceless Organization http://big.faceless.org

  • How to upload files through a servlet/jsp form?

    anyone know basically how to do this?
    i need to write a simple jsp form the can browse for a file on my machine, then upload it to a server in the usual html form manner.
    is this done with an i/o stream?
    thanks for any help!
    robSmyth
    [email protected]

    jspSmart has a free upload component you can use for HTTP file uploading. (http://www.jspsmart.com )
    Also, O'Reilly has an open source package you can use. (http://www.oreilly.com or http://www.servlets.com )
    Another option is dotJ, which has an upload tag in its tag library. Benefit of this library is that it has a much more compehensive set of JSP tags. (http://www.dotjonline.com )

  • Processing a jsp file through a servlet first

    At my company we have a lot of code tied up in servlets for our website. We would like to integrate JSPs along side the servlet architecture. We need to process the html files though both our serlvet architecture (Our website menu system and security are handled here) and the jsp tags.
    Here is what currently happens. We write a webpage, the servlet archtecture process the pages, doing substitutions on specific objects and running code in specific objects to build the html that is sent to the users browser. Instead of immediately sending the output to the users browser, i'd like to process it through the jsp servlet first. How would I go about running the newly substituted code through the jsp engine?
    Thanks in advance,
    Jeff

    That I probably wasn't clear enough with what is happening on our site.
    Let me walk you through how our site works.
    Here is an extremely simple page, and i'll walk you through what happens.
    <HTML>
    <HEAD></HEAD
    <BODY>
    Welcome {!s:username!}
    <!--#SQLLOOP name="SELECT" QUERY="SELECT year, name FROM programs where program_group_id = 35"-->
    {!r:select:name!}--- {!r:select:year!}
    <!--#/SQLLOOP-->
    </BODY>
    </HTML>When that page is called, the servlet starts. It opens up the file, does a substitiution on {!s:username!} for the username variable from session data. It then will execute a javaclass for the SQLLLOOP statement and output the year and name for all values where the program_group_id = 35. After the substitutions are done, then spits the html back at you.
    Now what I would like to do is to get this code to play nice with JSPs.
    the <jsp:include> tag does not appear to work.

  • Opening multiple excel files thorugh a servlet

    Hi
    In my system , i have excel reports in my server disk . And i am opening the excel files through an servlet class like /viewReport.do?id=23 .....and thus from the servlet will open my excel file .
    After opening one excel file , i try to open another excel by clicking that link , then my system often hangs else excel shows an error saying "a report with name viewReport.do is already open " even though both of these files are different on the server
    How can i avoid this ??
    The reason why i am opening the excel file through a servlet is , i need to perform some operations before opening that excel report
    Can any one let me know how to go abt this ??

    I had a similar porblem....
    I got some help from...http://www.javaworld.com/javaworld/jw-10-2006/jw-1019-xmlexcel.html?page=1...
    This is my code in servlet...
    HSSFWorkbook wb = new HSSFWorkbook();
         HSSFSheet spreadSheet = wb.createSheet("Users");
         spreadSheet.setColumnWidth((short) 0, (short) (256 * 25));
         spreadSheet.setColumnWidth((short) 1, (short) (256 * 25));
    //     Creating Rows
         HSSFRow row = spreadSheet.createRow(0);
         HSSFCell cell = row.createCell((short) 1);
         cell.setCellValue("Year 2005");
         cell = row.createCell((short) 2);
         cell.setCellValue("Year 2004");
         HSSFRow row1 = spreadSheet.createRow(1);
         HSSFCellStyle cellStyle = wb.createCellStyle();
    cellStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
    cellStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
    cell = row1.createCell((short) 0);
    cell.setCellValue("Revenue ($)");
    cell = row1.createCell((short) 1);
    cell.setCellValue("25656");
    cell = row1.createCell((short) 2);
    cell.setCellValue("15457");
    FileOutputStream output = new FileOutputStream(new File("/tmp/Users.xls"));
    response.setContentType("application/vnd.ms-excel");
    response.setHeader("Content-Disposition", "attachment;filename=Users.xls");
    ServletOutputStream out = response.getOutputStream();
    wb.write(output);
    output.flush();
    output.close();
    forward = null;
    In firefox i get the download dialog box but not able to open in from there,i need to save it and then open. In IE i dont get the dialog box instead the excell open inside the browser......Please help me to open a excel sheet onclick on a link "Export to excel" in jsp......
    Thanks in advance...
    Message was edited by:
    onlycoding

  • File Mapping from Servlet to client

    Hi,
    I want help in Servlets....
    My problem is, i am having one servlet and one client(Html) and one imageFile. My servlet knows the filePath, now it has to process the filePath so that the imageFile is displayed in Html. Now, the issue is in servlet is there any other procedure other than streaming the file in to ServletoutputStream??? I know that the following code solves my problem,
    File f = new File("F:\\Images\\2\\3\\2004\\12282004\\08\\1.jpg");
    byte[] imageData = new byte[(int) f.length()];
    FileInputStream fis = new FileInputStream(f);
    fis.read(imageData);
    response.setContentType("image/jpeg");
    ServletOutputStream out = response.getOutputStream();
    out.write(imageData);
    But what I want to know is, instead of Streaming the file into byteArray and set into ServletOutputStream, is there any other alternative???
    Thanks in advance
    Regards,
    Rama Sarma Vemuri L S K
    Mobile: +91-9885584568

    Hi,
    If we stream and send, it ll be taking much time in case of bigger images. So, I am trying like this. What I do os, in my Img tag, i ll call servlet which fetches me the URL of image and I ll the display the same. This is what I want to achieve. Can you help me out???

  • Please Help ! How would i Read xml file through servlet

    My requirement is that i have to make a stock exchange streamer.
    i am making an applet to show real time data to client. i had succeded in applet-servlet communication, but i m getting problem in
    parsing the xml files inside a servlet and throw it to applet again.

    I would suggest that you find out what the problem is, then. Once you find that out you will be far ahead of anybody else reading this post, because they have absolutely no idea what your problem is.

  • Send many files through a socket without closing Buffered Streams?

    Hi,
    I have an application that sends/receives files through a socket. To do this, on the receiver side I have a BufferedInputStream from the socket, and a BufferedOutputStream to the file on disk.
    On the sender side I have the same thing in reverse.
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)
    therefore, how can I tell the receiver that it has reached the end of a file?
    Can you show me any examples that send/receive more than one file without closing any streams/sockets?

    Hi,
    As you know I can't close any stream, ever.. because that closes the underlying socket (this seems stupid..?)Its not if you want to continuosly listen to the particular port.. like those of server, you need to use ServerSocket.
    for sending multiple files the sender(Socket) can request the file to server (ServerSocket). read the contents(file name) and then return the file over same connection, then close the connection.
    For next file you need to request again, put it in loop that will be better.
    A quick Google gives me this.
    Regards,
    Santosh.

  • Write out file through servlet

    Hello all,
    I wish to write out a file when a servlet is requested; however the file may be quite large and take a couple of seconds (approx 10) to write out. This results in a ten second delay for the user. I wish to offset this delay so the servlet continues executing returning the response and the file is written out in some form of background process.
    Could someone point me in the right direction?
    Thanks
    John

    Write up a Thread class to do the file writing for you. Your servlet will only start the thread with the required arguments and will generate the response without waiting for the thread to complete.

  • Transfering a file through Socket programming

    Hi all,
    I want to return a file from server to client through a socket. I tried using ObjectOutput Stream where in I returned a java.io.File from server. But at client side when I say file.getLeangth() it comes as 0 and if I try to assign FileInputStream on the object it throws an exception as the file not found as the path associated with the file will be of Server.
    So can anyone help as to how to transfer a file through socket programming???
    thx in advance
    MK

    java.io.File is NOT the contents of the file. It really just represents the path.
    If you want to transfer the file's contents, you'll have to use a FileInputStream or FileReader, read from it, and then write the bytes or chars on the wire.

  • Sockets: can only send once file through

    Hi,
    I am using sockets to send text and files to a client on a Clio. I want to send multiple files through. However, only the first file goes through. The rest are never received (although they are uploaded). My question is:
    Why can not send anything through the socket (text or files) after the first file is sent?
    The fileSend() is on the server side, fileReceive is on the client side.
    public static void fileSend (Socket uploadSocket, String source) {
         try {
             InputStream inFile = new FileInputStream(source);
             InputStream in = new BufferedInputStream(inFile);
             OutputStream out = new BufferedOutputStream(uploadSocket.getOutputStream());
             System.out.println("Sending " + source + ".");
             int data;
             int bytes = 0;
             while ((data = in.read()) != -1) {
              bytes++;
              out.write(data);
             bytes++;
             out.write(data);
             if (in != null) in.close();
             if (out != null) out.flush();
             System.out.println("Upload complete: " + bytes + " Bytes!");
         catch (Exception e) {
             System.err.println("Couldn't upload " + source + ": " + e.getMessage());
       public static void fileReceive (Socket downloadSocket, String destination) {
         try {
             InputStream in = new BufferedInputStream(downloadSocket.getInputStream());
             OutputStream outFile = new FileOutputStream(destination);
             OutputStream out = new BufferedOutputStream(outFile);
             System.out.println("Downloading data to " + destination + ".");
             int data = in.read();
             int bytes = 0;
             while (data != -1) {
              bytes++;
              out.write(data);
              data = in.read();
             bytes++;
             if (out != null) {
              out.flush();
              out.close();
             outFile.close();
             System.out.println("Download complete: " + bytes + " Bytes!");
             in.skip(in.available());
         catch (Exception e) {
             System.err.println("Couldn't download " + destination + ": " + e.getMessage());
        }Thanks,
    Neetin

    I think its better to pass the outputstream to the filesend() method and inputstream to fileReceive() method
    something like this:
    OutputStream out = new BufferedOutputStream(uploadSocket.getOutputStream());
    public static void fileSend (OutputStream os, String source) {
      //write your file onto the output stream
    InputStream in = new BufferedInputStream(downloadSocket.getInputStream());
    public static void fileReceive (InputStream is) {
      //Read from the input stream
    }This should work.. Good luck

  • Can't play mp3 file through RTP

    I created an server/client application to play remote file through RTP using JMF. However, it works with *.wav and video track of mpg file only, can't work when playing *.mp3 and audio track of mpg file. Do anyone know the reason?

    No any errors.
    I just follow the code sample "AVTransmit2" & "AVReceive2" and change the format.
    I change the format of mpg file audio stream to G723, it works now! So I think I used wrong format, but I found there is only two supported RTP format for mp3 file and it doesn't work for both of them.

  • URGENT.........File Upload using Servlets and jsp

    I am a new servlet programmer.......
    iam using tomcat server......
    can any one pls help in writing code for file upload using servlets and jsp without using multipart class or any other class like that....
    Please URGENT..

    Slow down! "Urgent" is from your perspective alone. I, myself, am not troubled or worried in the least.
    hi ugniss
    thanks for ur reply....sorry i was not
    y i was not asked not to use multipart class or any
    other class like that...is there any other
    possibility to do file uploading from jsp to
    servlet...
    Just as an aside, a JSP is a Servlet. But even if I move beyond that, the question does not make sense. If you want a "JSP to upload to a Servlet", then simply do so in memory. You are still (likely) within the same scope of a given request. However, if instead you are referring to a JSP that is displayed on a browser, then really you are talking about HTML, which is what the browser will receive. And since you are now talking about a browser, your only real, viable option is a multi-part file upload. So, it is either server or it is browser. And either way, the question leads to very established options, as outlined above.
    the main concept is.. in the browser the user selects
    a particular file and clicks the button upload..after
    clicking upload the jsp should sent the file to the
    servlet in streams...there the servlet gets in and
    saves in a server location........this is wat i hav
    to do...
    Okay. So, after reading my previous (redundant) paragraph, we have arrived at the crux of the issue. You have a JSP that will be output as HTML to a client (browser) which you want to upload content to your server (handled by a Servlet). So, you are now stuck again with multi-part. The requirement to not use multi-part is non-sensical. You can overcome it, say, if you write your own applet or standalone Swing client. However, if your users are invoking this functionality from a browser, you are limited by the options that W3C has provided you. Use multi-part.
    is there aby possibilty to do this.....can any one
    pls help....Take the advice to download and review Jakarta Commons FileUpload. Inform your management that their requirement makes no technical sense. Research on your own. There are dozens of examples (and tutorials) on file upload using multi-part. Embrace it. Live it. Love it.
    - Saish

  • How to transfer a binary file through the socket?

    hi,
    i have a problem when I want to transfer a binary file through the socket. On the server side we write a program with C. On the client side with use java. The socket worked fine when we transfer some asci files. But failed when transfer the binary file. How to solve the problem? Can someone give me some advice? Thanks a lot.
    sincerely,
    zheng chuanbo

    i use streams to read the binary file. The problem is I don't know when the transfered stream finished. With text file I can recognize the end of the transfer by a special string, but how to deal with the end of a stream? should the server send an "EOF" or something else to the client to notify the end?

Maybe you are looking for

  • Imported archive : issues in loading referenced XSDs

    hello experts, I am validating XML messages in XI using a Java mapping and by loading the XSDs at runtime. I am facing a typical problem when my XSDs import / include other XSDs and below is the situation. I have a Java mapping class say Validator in

  • Parsing Non English characters from OPEN DATASET

    Hi Team, I'm try to download the .txt file using the OPEN DATASET in the windows environment from application server, system language is set up for English. The problem is, in the .txt file some times I will be getting the non-English characters (Spa

  • IPod stuck skipping at the beginning of every song

    My iPod isn't frozen, but it won't play any songs past the first second. My touch wheel isn't working properly for some reason so I can't reset it. Any advice on how to proceed? Updating it through iTunes isn't working either.

  • Hard Drive Crashed with Grey Apple Screen and Spinning Circle

    I need some help!! My G5 desktop computer had Font error, and then it crashed. I pressed the power button to restart and it won't booth up! All I get it the Grey Apple Screen and Spinning Circle with loud fan noise. I've tried using the install CD to

  • White frame around .ai object

    Hi, I've an illustrator object placed on my InDesign document. When I'm working, everything is OK. But when I export it into a PDF file, a white square (wich looks like the ArtBoard) appears around this object. It's very annoying!! May somebody help