Sending a file to the Response failure

Hello everybody,
I have to send a file to the response for the browser to show a save/open file dialog box to the user, so he/she can download it and save in in his/her local file system. As expected the file is stored in a specific directory in the file system of the server.
What I did was to call this method within a commandLink component:
public String downloadDB(){
      FacesContext context = FacesContext.getCurrentInstance();
      HttpServletRequest request = ( HttpServletRequest )
                                 context.getExternalContext().getRequest(  );
      HttpServletResponse response =
         ( HttpServletResponse ) context.getExternalContext().getResponse();
      String filePath = null;
      int read = 0;
      byte[] bytes = new byte[1024];
      filePath = getMyDBPath();
      response.setContentType("application/pdf");
      FileInputStream fis = null;
      OutputStream os = null;
      try {
         fis = new FileInputStream(new File(filePath));
         os = response.getOutputStream();
         while((read = fis.read(bytes)) != -1){
            os.write(bytes,0,read);
         os.flush();
         os.close();
      catch ( FileNotFoundException e1 ) {
         logger.error(e1);
         logger.info(e1.getMessage());
         request.setAttribute("errors", "File Not Found.");
      catch ( IOException ioe ) {
         logger.error(ioe);
         logger.info(ioe.getMessage());
         request.setAttribute("errors", "Error reading file.");
      return "";
   }After the user clicks on the commandLink, the page I'm working on, gets refreshed and at the top of it appears the text of the file I tried to download. This is not the expected behaviour, what should I do?
thanks a lot,
Johnny

I have found the solution, some googling and in another differente JSF forum.
what I missed was to include in the header this:
response.setHeader("Content-disposition", "attachment; filename="+filename);With that line it works perfect.
thanks.

Similar Messages

  • Trying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.

    rying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.
    Does anyone know how to fix this?

    What EXACT version of Photoshop CS4 are you running?  You should be on Photoshop CS4 v 11.0.2.
    Also run Apple's software update to see whether it offers you the latest Epson update:
    Printer Driver v9.33
    Epson Stylus Pro 3880, Drivers & Downloads - Technical Support - Epson America, Inc.
    MOST IMPORTANTLY:  have Photoshop re-create its own Preferences:
    To re-create the preferences files for Photoshop, start the application while holding down Ctrl+Alt+Shift (Windows) or Command+Option+Shift (Mac OS). Then, click Yes to the message, "Delete the Adobe Photoshop Settings file?"
    Note: If this process doesn't work for you while you're using a wireless (Bluetooth) keyboard, attach a wired keyboard and retry.
    Important: If you re-create the preferences by manually deleting the Adobe Photoshop CS6 Settings file, make sure that you only delete that file. If you delete the entire settings folder, you also delete any unsaved actions or presets.
    Reinstalling Photoshop does not remove the preferences file. Before reinstalling Photoshop, re-create your preferences.
    NEW Video! Julieanne Kost created a video that takes you through two ways of resetting your Photoshop preferences. The manual preference file removal method is between 0:00 - 5:05. The keyboard shortcut method is between 5:05 - 8:18. The video is located here:
    How to Reset Photoshop CS6’s Preferences File | The Complete Picture with Julieanne Kost | Adobe TV
    Mac OS
    Important: Apple made the user library folder hidden by default with the release of Mac OS X 10.7. If  you require access to files in the hidden library folder to perform Adobe-related troubleshooting, see How to access hidden user library files.

  • Every time I send a file to the TRASH, finder ask me to type my system password to complete the removal and wasn't like this before. How do I make to work like it was before? Thanks.

    Every time I send a file to the TRASH, finder ask me to type my system password to complete the removal and wasn't like this before. How do I make to work like it was before? Thanks.

    http://www.thexlab.com/faqs/trash.html

  • How do you send a File from the Clinent End To the Server?

    Hi, I'm jut learing Java and am tring to send a file from the Cleints end to the Servers' end, I know how to do this in Php, but its some what different in Java, i know where is a File Class which i can post the information into but for some reason it woudn't work
    <%@ page import=" javax.servlet.*, java.io.File" %>
    <%
    String fullname, emailadds, genre, filename;
    fullname = request.getParameter("Name");
    emailadds = request.getParameter("email");
    genre = request.getParameter("genre");
    filename = request.getParameter("clip");
    File file = new File();
    file.isFile();
    if (file.isFile())
    out.print("File is true");
    else
    out.print("file ain't there");
    %>
    just as a tester i tried this to see if file is being read, but it won't compile
    I keep getting this error sign! Have i missed out a lib or somthing?
    \upload_jsp.java:52: cannot find symbol
    symbol : constructor File()
    location: class java.io.File
    File file = new File();

    Sham, dont show your anger... and dont use provocative words...
    Now, coming to your problems.
    your jsp/html should contain some thing like
    <form action="/uploadServlet" method="post">
    <input type="file" name="file"/>
    <input type ="submit" value="upload"/>
    </form>and for servlet code, refer to
    http://forum.java.sun.com/thread.jspa?threadID=516176&messageID=2461686
    or the easiest way would be to use 'commons-fileupload' api available on http://jakarta.apache.org/commons/

  • How to send a file top the default printer?

    Hello,
    I have generated, using Java code, a certain HTML file and wrote it to a certain location on my local machine. I would like now to automatically send this file for the default printer for printing, this way the user won't have to manually open the file and select
    file->print from the browser window and then print it.
    How can I acomplish this?

    hi
    good
    how can you identify which file you r going to print and which file you r going to print.if you r going to print all the file from that particular location than you can do it through jsp, but i dont think it can be done automatically, the user has to select the particular location where you have stored the file in you hard disk and i will go for printing.
    Thanks
    mrutyun

  • ITunes does not delete songs  -- Send song files to the Trash for deletion

    27May2012
    Apple Support:
    I have Itunes on an external drive.  I put the (song) files on another external drive for storage becasue the itunes drive is full.
    After copying the files, I tried to delete the songs.  I had the option to keep the files or send them to the trash.
    I selected the send to trash option, then went to the Finder to empty the trash.
    The files were taken off the library, but the files were not deleted.  My hard drive is still very full. 
    How do I delete the files  -- remove them from my hard drive.
    Anohter issue:
    I tried the same thing earlier this morning.  I may need to reinstall the songs on Itunes (once I get itunes to delete the files from the hard drive).  
    I appreciate any help you can give me.
    <Email Edited By Host>

    It's definitely intel, why wouldn't it be?
    I don't know.
    You list a G5.
    A G5 is a PowerPC chip made by Motorola, not Intel.
    And G5 Macs/iMacs have not been made for +4 years.

  • How to attach XML file in the response of Web Services

    Hi
    I am new to the WEB SERVICE. this my requirement.
    I need to make a class file a web service. and i need to get data from the data base and attach it in the response. I need to use SOAP MEssaging for this. so how to call the service from the JSP and how to get the data from the response,Before that which technology i need to use for this requirement. Plz let me know how to accomplish this task. I have gone thur lot of tech stuff and i am confused a lot, what to use and how to use. Will any one help me out.
    Thanks
    Vidya

    Hey VP, thanks for replyng.
    I have read the codes from a book and havesome code for client. The server side is yet to be done....but I have problems in compiling them as I am Unable to import javax.xml.soap.*;
    This is basically a request to the Server asking it to find the match of the word "Mickey" from the XMLfile at the server...JAXRPC is involved(I Presume:) There are some supporting files.........hey But it doesn't compile only here. Hope it does in yrs
    *******The client..........**********
    * Client
    package com.aby.jwsdp.soap.client;//the package
    import javax.xml.messaging.URLEndpoint;
    import javax.xml.soap.SOAPConnectionFactory;
    import javax.xml.soap.SOAPConnection;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.Source;
    import javax.xml.transform.stream.StreamResult;
    import com.aby.jwsdp.soap.client.Fault;//supporting file
    import com.aby.jwsdp.soap.client.RequestMessage;//supporting file
    public class Client {
         static final string SERVICE_ENDPOINT="http://localhost:8080/chap/servlet/chap.RecieveServlet";
         public static void main(String args[]) {
              if(1!=args.length) {
                   System.err.println("Usage: java "+"com.aby.jwsdp.soap.client.Client <name>");
              } else {
                   new Client(args[0]);
         public Client(String name) {
              try{
                   URLEndpoint endpoint = new URLEndpoint(SERVICE_ENDPOINT);
                   SOAPConnectionFactory scf=SOAPConnectionFactory.newInstance();
                   SOAPConnection connection = scf.createConnection();
                   RequestMessage reqMsg = new RequestMessage();
                   reqMsg.setName(name);
                   SOAPMessage replySOAP = connection.call(reqMsq.getMessage(),endpoint);
                   if(Fault.hasFault(replySOAP)) {
                        Fault fault = new Fault(replySOAP);
                        System.err.println("Recieved SOAP Fault");
                        System.err.println("Fault Code: "+fault.getFaultCode());
                        System.err.println("Fault string: "+fault.getFaultString());
                        System.err.println("Fault detail: "+fault.getFaultDetail());
                   }else {
                        ResponseMessage respMsg = new ResponseMessage(replySOAP);
                        String responseValue = null;
                        try{
                             responseValue = respMsg.getValue();
                             System.out.println("Response: "+responseValue);
                        }catch(SchemaException e) {
                             System.err.println("Parsing error");
                   connection.close();
              }catch(EXception e) {
                   System.err.println(e/toString());
    /*@author Aby
    *Fault.java
    package com.aby.jwsdp.soap.client;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.soap.SOAPPart;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPBody;
    import javax.xml.soap.SOAPFault;
    import javax.xml.soap.SOAPException;
    import javax.xml.soap.Detail;
    import javax.xml.soap.DetailEntry;
    import java.util.Iterator;
    public class Fault {
         protected SOAPFault soapFault;
         public Fault(SOAPMessage msg) throws SOAPException {
              SOAPPart soapPart = msg.getSOAPPart();
              SOAPEnvelope envelope = soapPart.getEnvelope();
              SOAPBody soapBody = envelope.getBody();
              soapFault = soapBody.getFault();
         public static boolean hasFault(SOAPMessage msg) throws SOAPException {
              SOAPPart soapPart = msg.getSOAPPart();
              SOAPEnvelope envelop = soapPart.getEnvelop();
              SOAPBody soapBody = envelop.getBody();
              return soapBody.hasFault();
         public String getFault() {
              return soapFault.getFaultCode();
         public String getFaultString() {
              return soapFault.getFaultString();
         public String getFaultDetail() {
              String ret = null;
              Detail detail = soapFault.getDetail();
              if(null!=detail) {
                   Iterator it = detail.getDetailEntries();
                   if(it.hasNext()) {
                        DetailEntry detEntry = (DetailEntry)it.next();
                   ret = detEntry.getValue();
              return ret;
    * RequestMessage.java
    package com.aby.jwsdp.soap.client;
    import com.aby.jwsdp.soap.client.Client;
    import javax.xml.soap.MessageFactory;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.soap.SOAPPart;
    import javax.xml.soap.SOAPEnvelope;
    import javax.xml.soap.SOAPBody;
    import javax.xml.soap.SOAPElement;
    import javax.xml.soap.SOAPException;
    public class RequestMessage {
         protected SOAPMessage soapMessage = null;
         public RequestMessage()
         throws SOAPException {
              MessageFactory mf = MessageFactory.newInstance();
              soapMessage = mf.createMessage();
         public void setName(String name)
         throws SOAPException {
              SOAPPart soapPart = soapMessage.getSOAPPart();
              SOAPEnvelope envelope = soapPart.getEnvelope();
              SOAPBody body = envelope.getBody();
              SOAPElement requestElement;
              requestElement = body.addChildElement(envelope.createName("GetValueByName","myns","www.syngress.com/JWSDP/soap-example"));
              SOAPElement paramElement;
              paramElement = requestElement.addChildElement("name");
              paramElement.addTextNode(name);
         public SOAPMessage getMessage() {
              return soapMessage;
    check this out then we will see

  • How to send a file through the portal

    Hello,
    I have a problem in sending the file. I have selected a file kris.ppt and from context menu, I have selected sent to option and I have sent a file. I got a copy of that to my lotus notes but in that I had a format as kris.ppt.html. I cannot open the file. I can open the file when the portal is running. But I want to open the file when the portal is closed. Can anyone tell me the solution.
    cheers
    kris

    Hello Shankar,
    I tried that option also by default I'm getting 2 options.
    One is the kris.ppt.html and other is the kris.ppt. I cannot open the first one rather I could open the second. I can open the 1st one if the portal is opened. Can you suggest anything regarding that one.
    cheers
    kris

  • Sending uploaded file to the approver using GP Process

    Hai all,
    i my project i need to send the resource files for approver ...
    in my application i have created three actions under one sequencial block ..i need to send the user uploaded files to the three approvers .....

    Hi Ravi,
    You can send email with attachment to multiple approver's using webdynpro api. Please check below link -
    http://wiki.sdn.sap.com/wiki/display/WDJava/Sendmailwithattachmentusingwebdynpro+API%27s
    Regards,
    Sen

  • Sending DME file to the bank using RFFOUS_T?

    Hi all,
    I understand that we use RFFOUS_T to create the DME file but do we use the RFFOUS_T to send the generated DME file to the bank as well? I mean the RFFOUS_T is not linked to the banking system right? Is it I should use t-code: FDTA to download the DME file to my local PC and email the downloaded DME file to the bank? Anyone can clarify on this?
    Thanks.

    Yes.  You can use RFFOUS_T to generate the payroll DME file (use the pre-DME program first, of course).  Then, as you said, go to FDTA to download and send to the bank.

  • Send a file to the printer!

    Hello,
    is it possible to send a file, that is generated with the
    printer-driver, to a network-printer? This should be done with LabVIEW
    6i
    Jens

    [email protected] (VI Guy) wrote in <5065000000050000007CAB0000-1031838699000
    @exchange.ni.com>:
    >Yes and no.
    >
    >The printer has to be of the type that allows this (I don't know the
    >exact requirement but some printers allow it and others don't).
    >
    >Set up your computer so the network printer is "mapped" to printer
    >port like "LPT1" or "LPT2" (If I recall this requires you to answer
    >yes to the "Do you print from MS-DOS applications?" during the "Add a
    >Printer" wizard).
    >
    >Then, you will need to use the "Shell Exec.vi" and do a "COPY /B
    >Filename.bin LPT1", given that "Filename.bin" is the file you created
    >with the print driver and "LPT1" is the port you mapped your printer
    >to.
    >
    Alternatively if it's just a plain old text printer, you can use the serial
    vi's
    to send the text directly to a line printer using COM10. Note that you
    will have to include a line in your labview.ini file (and in the ini file
    with your built application) that allows you to access com10. The line is
    something like:
    "serialDevices=com1;com2;com3"
    but a search on using the line printer on the NI website will reveal the
    correct key and entry.
    Alexander C. Le Dain, PhD
    ICON Technologies Pty Ltd
    http://www.icon-tech.com.au
    * The LabVIEW FAQ http://www.icon-tech.com.au/thelabviewfaq.html *

  • Issues with Receive Adapter receiving a file that has not completed uploading while send multiple files on the Send Adapter

    Hello,
    I am only a few weeks old into BizTalk so I am new to this application. 
    The pieces I have for my development environment consists of the following:
    FTP Server ---[SFTP Adapter]---> BizTalk 2013 ---[FILE Adapter]---> Internal Network Share Drive
    I currently configured a simple PassThru, One way Receive/Send in BizTalk where the Receive Port receives a file via SFTP 
    Adapter from our FTP server and the Send Port sends the file via the FILE Adapter to our Internal Network share drive. 
    The setup works great with small files.  However, when I receive a large file on the FTP server, the Send Port sends multiple instances of the file on the FTP server because the Receive Adapter sees that the file is there, but not yet
    fully uploaded.
    Can someone please guide me as to how I can determine when a file is fully uploaded to the FTP server before the Receive Adapter fires?
    Thanks,
    Mitch

    Yap BizTalk does not have control over locking the file during read/write Operation and its the third party which need to take care of this (by rename the file after upload ) .
    If the file size is too large I would suggest to bypass the message box as it has performance bottleneck during peak hours 
    Apart from being repetitive, this is not good advice.  There is no indication that the file is too large or will cause any "performance" issues.
    The concurrency problem can happen with a file of any size.

  • Running Yosemite, printing to xerox c75 digital press. InDesign will send a file to the printer, then crashes every time. I know there was a patch for this problem. Where do I find it?

    Whenever I send a file to my Xerox C75 from my Mac (Yosemite), the file goes to the printer okay, then InDesign crashes.
    I think there is a patch specifically for this issue. Where do I find it?

    Yes, I have Fiery Hot Folders Console.  That is certainly an alternative that should work as I can then avoid having to choose Fiery Features from the print dialog box in order to choose the paper tray and other features I need.
    I am about to try a clean install of OS 10.9.3, and I am not the least bit happy about it.  Adobe CC is my main set of go-to applications for my work, and those are the only applications that give me ANY problems with printing.  I have forked out real money on different versions since I started using Adobe in the late 1990's, and my troubles seem to increase with every new release.

  • Abstract Portal Component: How to inclue a HTML file into the response?

    Hi experts,
    i am currently working on the problem, that i want to access KM inside my AbstractPortalComponent in order to retrieve a HTML File.Afterwars i want to include this file into my IPortalComponentResponse.
    IPortalComponentResponse offers the method include(IPortalComponentResponse , IResource)
    Is it possible to use this method to achieve my goal?
    I have tried this approach:
    IResourceContext resourceContext = new ResourceContext(requester);
    RID rid = RID.getRID("/documents/test.gif");
    IResource resource = ResourceFactory.getInstance().getResource(rid,resourceContext);
    response.include(request,resource);
    But the problem is that this IResource doesn't match the IResource that is needed for this method.
    My IResource belongs to com.sapportals.wcm.repository.IResource
    But the Methos just works with com.sapportals.portal.prt.resource.IResource
    So can you help me on this one?:)
    With Best Regards
    Marcus

    Hi,
    read the contents of the resource and put them to the output.
    Dumb but working piece of code:
    private String renderResource(IResource resource, boolean html) {
              StringBuffer buf = new StringBuffer("");
              try {
                   IContent content = resource.getUnfilteredContent();
                   if (content != null) {
                        InputStream is = content.getInputStream();
                        byte[] bytes = new byte[(int) content.getContentLength()];
                        int i = is.read();
                        int count = 0;
                        while (i != -1) {
                             char b = (char) i;
                             bytes[count] = (byte) i;
                             count++;
                             i = is.read();
                        buf.append(new String(bytes, "UTF-8"));
                        if (html) {
                             buf.append("</br>");
                        } else {
                             buf.append('\n');
              } catch (Exception e) {
    // do something
              return buf.toString();
    hope this helps,
    Rmano

  • I never set a password for my acrobat and it is locking my out of changing the password settings. I am trying to send a file and the reciever cannot access

    help

    There are quite a lot of possible things that are going on. Can you let us know
    1. What system you have (e.g. Windows 7, Mac OS Mavericks)?
    2. What version of Acrobat or Adobe Reader you have?
    3. WHO gets the message about a password (you or the receiver, or both)?
    4. What is the full text of the message, if you get it?
    5. If the receiver gets it, what security do you set on the file?

Maybe you are looking for

  • Install error message after logging off OSX

    When logging out of Mavericks, I get an error message on the screen as it goes to black that asks me do I want to abort the installation or continue with the installation. It closes out to the login screen after pressing either button you press, one

  • Using Time Machine to restore external hard drive data

    I have been using a Mac Mini running 10.6.8 for years as a media server.  I have always been very careful to maintain backups of everything, and the inevitable did happen - the hard drive containing all my media did fail. To clarify my set up, my Mac

  • Using plain j2se adapter

    Hi Experts, This is regarding j2se adapter engine. I dont have any idea to use j2se adapter engine. I checked this URL: http://<IPAddress>:8200 , changing the ip but it is not working. How can I check whether it is installed in my system ? Thanks Rab

  • Itunes has stopped working on ps w/win 7 prof what can i do?

    i have had itunes working up to dec 2011. now it just stops as soon as itunes is started. i have not added any software except uniblur registrybooster. what can i di? since i just ordered a new ipod touch 32mb. thanks john

  • Can I sign a Microsoft Word Document with the digital signature from a MIlitary issued CAC card?

    Is it possible to sign a MS Word doc with the digital signature froma  Military issued CAC card? It is easily done in Adobe but, I cannot find any guidance for MS Word docs.