Download any type of files from JSP/Servlet

Hi,
I understood that if I want to download a file from a JSP or a Servlet I have to set the content type to the MIME type of the file itself.
And then I have to set the Content-Disposition to "attachment; filename=\"" + file_name + "\";" if I want the Open/Save window displaied by the browser (otherise the "inline;...").
How can I download a file if I don't know its MIME type? Am I suppose to use the "application/octet-stream" MIMETYPE?
Where can I find documentation and sample code for doing it?
Are there any free packages available to do so?
Thank you very much

Look at http://www.javaworld.com/javaworld/javatips/jw-javatip94.html for the basic method. This article also refers to the RFCs on MIME types which should answer your questions on what type to use for unknown or binary data.

Similar Messages

  • My firefox 17.0.1 on Win 7 64 bit SP1 still crashes when I download ANY type of file EVEN browser.download.manager.scanWhenDone is false ... WHY ???

    my firefox 17.0.1 on Win 7 64 bit SP1 still crashes when I download ANY type of file EVEN browser.download.manager.scanWhenDone is false ... WHY ???

    If that plugin isn't working properly then its developer needs to fix this via an update.
    Try to ask advice at the Free Download Manager forum
    *http://www.freedownloadmanager.org/board/

  • LR3 will not import any type of file from my HD

    LRv3.6. OS10.7.4. 9GB RAM. 700GB freespace.
    I'm used to easily importing RAW, Tiff and jpeg into LR3. For a reason unknown to me, LR3 now rejects all import requests.
    Recent RAW files are shot on 5d mk3 into Capture One Pro 6.4.3-64bit. I thought it would be the camera so I tried to import historic files from jobs that I had already proccessed in LR3 but still no luck.
    Tried importing regular tiffs, no joy either.
    Do any of you good people have any ideas?

    What error message are you getting?
    If LR says the files could not be read, the problem is probably that you don't have write permission for where you're copying the files to when you try to import. Yes, I know that the error message is backwards.
    Try importing with Add, so the files aren't moved or copied.
    If that isn't your problem, come back with a description of what is happening.
    Hal

  • Read xml file from jsp/servlet

    Hi all,
    I am a new comer to jsp and really appreciate if someone can help me on this:
    I will like to use a xml file to control access to my web app instead of using a database. Let say user.xml that will contains user name and password. Questions:
    1. where should I put this file? Under WEB-INF?
    2. In my jsp or servlet, how do i read the xml file, i mean how to i refer to the file (depend on question 1 as where the file should be placed)?
    Thank you very much.
    Sim

    Hi jlsim,
    you can place the xml file where you want, but remember that placing it under /WEB-INF is the most security way.
    I had a similar problem and I placed the xml file under /WEB-INF directory.
    To refer to it I did something like this:
    String realPath=getServletContext().getRealPath("WEB-INF/xml/workspaces.xml");//obtain the real path
    File f=new File(realPath);//obtain an instance of your file usable
    //to create an InputStream

  • I recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank"

    i recently updated my macbook, i don't know if that has any effect to my recent problem, but when i try to download and save .mp3 files from the internet, like i have done in the past, it downloads but not as an mp3 file, its "blank" and when i try to open it, i can't? I NEED HELP !

    Here is the download page

  • Whenever I open a file of any type, that file will open, as well as multiple other files I do not wish to open.  How do I prevent this from happening.

    Whenever I try to open a file of any type, that file will open, as well as several other files I do not wish to open.  How do I prevent this from happening?

    Dealing With The Resume Feature of Lion
    Managing Mac OS X Lion's application resume feature.
    If you shutdown your computer you should get a dialog asking if you want applications to resume on the next startup. Simply uncheck the box to prevent that from occurring. Open General preferences and uncheck the option to Restore windows when quitting and re-opening apps. You can also install a third-party utility to control resume features on individual applications: RestoreMeNot or Application State Cleaner.
    It is possible to completely stop the Resume feature although I'm unconvinced that it is that annoying. Nevertheless see the following:
    If you have not yet done so you must first make your /Home/Library/ folder visible. Open the Terminal application in the Utilities folder. At the prompt paste the following command line:
    chflags nohidden ~/Library
    Press RETURN. Quit the Terminal application.
    In the Finder navigate to the /Home/Library/Saved Application State/ folder. Delete the contents of the folder. Back up to the /Home/Library/ folder. Select the Saved Application State folder. Press COMMAND-I to open the Get Info window. In the Sharing and Permissions panel at the bottom click on the lock icon and authenticate. Set each of the listed entries to Read Only. Close the Get Info window.
    Quit all open programs except the Finder (this is very important.) Next, navigate to the /Home/Library/Preferences/ByHost/ folder. Look for a .plist file with "com.apple.loginwindow." in the file name followed by some numbers in hexadecimal. Select the file. Press COMMAND-I to open the Get Info window and in the Sharing and Permissions panel click on the lock icon and authenticate. Set each of the listed entries to Read Only. Close the Get Info window. If you also find a file with the same filename but with a last extension of ".lockfile," then you should delete it.
    The above should eliminate the Resume feature system-wide. Note that any future system updates or upgrades will likely undo these changes. You will then need to repeat this procedure assuming there are no major changes in OS X related to it.

  • When I opt to "download this as a file" from my email account, Firefox defaults to notepad to open the file. How can I change the default to MS Word?

    Question
    When I opt to "download this as a file" from my email account, Firefox defaults to notepad to open the file. How can I change the default to MS Word?

    Is FF downloading the file as a .txt file? If so, go to "Folder Options" in the windows control panel. Click on the "File Types" tab. Scroll down until you reach the TXT file extension. Look to see what that extension opens with (lower part of panel). It probably shows notepad. Click on the <Change> button. Scroll down until you find "Microsoft Word." Select it and click the <OK> button. That should show the TXT extension is now associated with Microsoft Word. Click the <Close> button at the bottom of the panel.
    If FF is downloading the file as any other type, use the same process as above except look for the corresponding extension instead. If the extension is not listed click on the <New> button and create an association using the extension in the file name and then associate it with MS Word.
    davewdan

  • Sending Mail from JSP-Servlet

    hi all,
    Can any one help me, how can i send the mail from JSP-Servlet.
    in Spring, we have a the following package to send mail,
    import org.springframework.mail.MailSender;
    import org.springframework.mail.SimpleMailMessage;
    import org.springframework.mail.javamail.JavaMailSenderImpl;
    Suggest me to solve the problem.
    Thanx in advance.
    Bala

    Hi balu,
    i already go thru that API. My problem is if i add any additional jar file for sending the mail from JSP or Servlets only. not in high technology.
    i mention spring as an example.
    so, kindly suggets me on that.
    Bala

  • PROBLEM while using URL in order to open a file from a servlet

    Hi,
    I am having a problem while trying to open a file from my servlet by using URL connection. Following is my code sample. what happens is when I first run my project it opens the file but after that when I rerun it again and again it sometimes opens it and sometimes not. if it can't open it it gives an error saying "the file is damaged and couldn't be repaired". I don't get any exceptions. if you guys can help me I will appreciate it so much... thanks.
    here is my code :
    URL url = new URL("http://demobcs.ibm.com:81/test.pdf");
    resp.setContentType(getContentType("http://demobcs.ibm.com:81/test.pdf"));
              ServletOutputStream sos = null;
              BufferedInputStream bis = null;
              try {
                   sos = resp.getOutputStream();
              } catch (Exception e) {
                   System.out.println("exception !!!!");
                   e.printStackTrace();
              System.out.println("burada2");
              try {
                   byte[] bytes = new byte[4096];
                   //bis = new BufferedInputStream(conn.getInputStream());
                   DataInputStream in = new DataInputStream(url.openStream());
                   //DataInputStream in = new DataInputStream(conn.getInputStream());
                   bis = new BufferedInputStream(in);
                   int j;
                   while ((j = bis.read(bytes, 0, 4096)) != -1) {
                        try {
                             sos.write(bytes, 0, 4096);
                             System.out.println("file is being read ...:");
                        } catch (Exception e) {
                             e.printStackTrace();
                   in.close();
                   bis.close();          
                   //sos.close();
              } catch (Exception e) {
                   System.out.println("exception :"+e.toString());
                   e.printStackTrace();
              }

    You are writing (<filesize> mod 4096) bytes of crap at the end of the file. Use your variable j instead for the number of bytes to write in your loop.

  • Copy any kind of file from content server to network directory

    Helli All
    The question:
    I nee to copy any kind of file from content server to any network directory.
    Explanation
    1. transaction CV02N
    2. There is attached file for a document in tab "Document data/Original"
    3. This file stored in content server
    4. I wrote program code that creates path of the stored file that finally looks like
    http://cont:8888/ContentServer.dll?get&Version=.....*...&compid=app1.doc
    where app1.doc is file's name and I have to copy this file into network directory.
    The problem is that this URL open the file instead of just pointing to him
    so that no function or method can't see this file and as the result I got message that
    the file doesn\t exist.
    Please, advice.
    Regards,
    Daniel.

    many many thanks for ur help. i really did not check the URLClassLoader properly.
    but i would like to hear a little more from u. i have another question. here in this code (provided earlier), i searched for attribute values in the manifest file, then again i load the required class file from the very url. is it not good to retrieve the whole jar file first, and then check attribute values inside manifest file and load the required class files from that jar file that is already downloaded without going to that url again? how can i do this?

  • How to call java class file from jsp

    hi
    we need to call java classes (which are written separately in .java file )from jsp file. we need it for our project if anyone knows about please reply us.
    bye
    siva sankari

    you can call the methods in a lot of ways. you could use scriptlets with the
    <%@ page import="package.class"%> and then inside instantiate an object
    <%
         MyClass mc = new MyClass(parameters if any);
         mc.theMethodYouWantToCall();
    %>or as Madathil has stated,
    or use the JSP tags
    <jsp:useBean id="anyname" class="classname"/>and then use the getProperty tag
    or even Custom Tags

  • How can I attach any type of file in forms runtime

    Hi Friends,
    I need some help from any one of you.
    Is there any possibility to attach any type of file in forms runtime?
    If there is, how can. Please let me know the code.
    Thanks

    I think that you are going to have to explain what you want to do more clearly...

  • Using a thread to write a file from a servlet

    Does anyone have some code that can help out my problem:
    I am writing a file from a servlet, but the servlet completes and loads another page prior to the file writing to disk being completed.
    I have tried using threads to stop the serlvet until the file has been completely written, but I am not experianced using threads properly, and so far have been unsuccesssful.
    I would sure appreciate some/any code to reference to overcome this problem.
    Thanks to any responses.
    Dale

    Hi the best idea for you is not to use thread, so that the file processing gets completed before your servlet start doing anything else..
    something like this.
    public void doGet(     HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
    System.out.println("Called Repo");     
    BufferedInputStream res = new BufferedInputStream((request.getInputStream()));
         File f= new File("img.jpeg");
         FileOutputStream fo = new FileOutputStream(f);     
              byte b[]=new byte[64];
              int line=res.read(b);
    while(line!=-1)
         fo.write(b);
         line=res.read(b);
    fo.close();
    //your remaining processing from here...
    regards

  • While downlaoding any type of file instead of showing the file size 'unknown time remaining' is showing?

    While downlaoding any type of file instead of showing the file size 'unknown time remaining' is showing? Please suggest solution to these problems?

    I followed ALL the Above suggestions to NO AVAIL!
    When I start a download, if I then Click PAUSE, it WILL NOT CANCEL & IT WILL NOT RESUME, just sits there stating "unknown time remaining"
    and I CAN'T GET RID OF IT!
    It would seem that Something Changed with the latest Firefox Beta Update that is causing this Anomalie.. Please FIX ASAP as I find this Very Annoying.
    With ANY Download in Limbo the Firefox Taskbar Icon displays a Partial Download Progress THAT NEVER CHANGES and I can not tell what Other Downloads are doing - It also Warns me that X-Number of Downloads are Still Pending when I go to Close Firefox, but as I stated, these Downloads are DOING NOTHING & CAN'T BE REMOVED!
    HELP! - BJ

  • My iOS customers cannot download the video clips I send via Adobe Send "Safari cannot download this type of file"

    My customers who use iOS cannot download the video files I send by Adobe Send "Safari cannot download this type of file" is the report they get. I have tried created a zip file of the clip but get the same result. Please help

    This error seems to point at a problem not directly related to the encoding. The message might be misleading but I read "Safari cannot download this type of file" as relating to the file type - the end of the name (perhaps MIME type setup, but let's start with the file type).
    But... some web searching finds others say that iOS cannot download files AT ALL because it has no filing system you can access. Clearly (?) you just want it to show the movie, but I don't know any more than that.
    Perhaps someone else has worked in this area. Also worth trying suitable iOS forum.

Maybe you are looking for

  • Is there a way to hide my Skype info from the publ...

    The reason I wish to do so is because I've been reciving an influx of of people wanting to find people to talk to, and have been sending me friend requests. However, I have no interest of talking to anyone who I have not met, unless it's from either

  • Battery failure OR charger failure?

    Quite suddenly I notice that the little light on the charger plug is no longer lighting. At the same time the power left in the battery is gradually falling when in use. So....... do I have a battery problem or a charger problem. The battery is about

  • Assign production order number to batch number automatically

    Hi All, I have been trying to assign production order number to batch number when clicked on create icon in t-code CO02, and successfully assigned Production order number to batch number through EXIT_SAPLV01Z_001 Question: Now i want to assign same p

  • Time Machine in a loop

    Out of the blue, I got this error message yesterday: Time Machine completed a verification of your backups. To improve reliability, Time Machine must create a new backup for you. Click Start New Backup to create a new backup. This will remove your ex

  • I have Adobe CS5 Master Collection. Will this machine run it alright?

    So I am in the process of shopping for a new computer to run some adobe software on. I have the Cs5 Master Collection, but generally I will only be using certain programs, specifically Photoshop, Illustrator, InDesign, Dreamweaver, occasionally Flash