Facing problem with posting Excel file for download - Content in browser

I am trying to post an Excel file to download from a servlet to a JSP. The content is written properly but to the IE browser and not in an Excel. I even tried giving the ContentType as Word/CSV etc. But nothing works, the content gets displayed only in the browser.
PLEASE HELP.
Code snippet in calling JSP:
DownloadServlet downServlet = new DownloadServlet();
downServlet.download(response);
Code in Servlet:
public class DownloadServlet extends HttpServlet{
public void download(HttpServletResponse response) throws IOException {
          /*PrintWriter out = response.getWriter( );
          response.setContentType("text/html");
          out.println("<H1>Hello from a Servlet</h2>"); */
     /*HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("Sheet1");*/
String strData = "This is a Test for Download";
byte[] b = strData.getBytes();
//response.reset();
response.setHeader("Content-disposition", "attachment; filename=" + "Download.xls");
response.setContentType( "application/msword" );
//response.addHeader( "Content-Description", "Download Excel file" );
ServletOutputStream out = response.getOutputStream();
out.write(b);
//out.flush();
out.close();          
}

Hi Naresh,
My thoughts on a possible solution, convert the last character value to a HEX value and check if it falls within the ASCII/Unicode CP range, Obviously this becomes easier if you are just looking at a single language character set.
The below FM and code helps you check if the character falls within the ASCII char set.
DATA: l_in_char TYPE string,
      l_out     TYPE xstring.
CALL FUNCTION 'NLS_STRING_CONVERT_FROM_SYS'
  EXPORTING
    lang_used                   = sy-langu
    SOURCE                      = l_in_char
  TO_FE                       = 'MS '
IMPORTING
   RESULT                      = l_out
  SUBSTED                     =
EXCEPTIONS
   illegal_syst_codepage       = 1
   no_fe_codepage_found        = 2
   could_not_convert           = 3
   OTHERS                      = 4.
IF l_out LT '0' OR l_out GT '7F'.
  WRITE: 'error'.
ENDIF.
Links: http://www.asciitable.com/
          http://www.utf8-chartable.de/unicode-utf8-table.pl
Regards,
Chen
Edited by: Chen K V on Apr 21, 2011 11:25 AM

Similar Messages

  • Problem with an excel file

    Dear All,
    I have a problem with an EXCEL file, i'm in a domain with windows server 2003 and all of the computer have windows 7, a user had open 3 weeks ago a fil excel after she gone on holiday so the file remain open (i don't know how) by she.
    I've try with all unlocker program to make the file deletable, but not work... it is very strange because if i try to open it with the account of the user that open the file appears always the same error (open read only)...
    Could you help me?
    thanks

    Hi,
    You may end the Excel process first, the “PsTools” have a pskill command that you can use to end a process remotely.
    Here’s a simple command:
    pskill \\computer –u username -p password  excel.exe
    For more information, please see the KB below:
    http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx
    Best Regards

  • InDesign CS5 causing problems with InCopy assignment file but not content files

    I'm having a strange InDesign/InCopy CS5 issue (Mac OSX 10.6.6; all system & Adobe updates are current).  In my InDesign doc I have one assignment file containing two content files. All of the InCopy pieces work fine in InDesign (i.e., I can check out/in, edit, etc.).  When I go to open the assignment file in InCopy, InCopy starts to open  it but then crashes. If I try to open each content file directly in  InCopy, no problem. I've tried deleting and recreating new assignments  in InDesign, but they all have the same result in InCopy.
    I think this actually is a problem with the InDesign file because if I export the InDesign file to IDML, then try to open the IDML file, InDesign crashes! I've trashed my InDesign preferences, made sure all cross-references are up to date, etc. Anybody have any ideas what else to look for in my InDesign file that might cause this problem?
    Thanks!
    Andrea

    Thanks John!
    1) Here are the first 10-ish lines from the crash report that is generated when I try to open the IDML file:
    Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
    0   ???                               0xa0c266f0 _XHNDL_trapback_instruction + 0
    1   com.adobe.InDesign.Indexing       0x20778192 GetPlugIn + 341394
    2   com.adobe.InDesign.Indexing       0x20779009 GetPlugIn + 345097
    3   PublicLib.dylib                   0x0129228b CScriptProvider::AccessProperties(IScriptRequestData*, IScript*) + 571
    4   com.adobe.InDesign.Scripting      0x1f4befe8 GetPlugIn + 166440
    5   com.adobe.InDesign.Scripting      0x1f4c2e31 GetPlugIn + 182385
    6   com.adobe.InDesign.INXCore        0x20641444 GetPlugIn + 45220
    7   PublicLib.dylib                   0x0142c9e8 CScriptDOMElement::GetMultipleAttributes(K2Vector<IDType<ScriptID_tag>, K2Allocator<IDType<ScriptID_tag> > > const&, adobe::version_1::vector<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue>, adobe::version_1::capture_allocator<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue> > >&) + 280
    8   PublicLib.dylib                   0x0142bd38 CScriptDOMElement::InsertProperties(adobe::version_1::vector<KeyValuePair<IDType<ScriptID _tag>, ScriptData>, adobe::version_1::capture_allocator<KeyValuePair<IDType<ScriptID_tag>, ScriptData> > >&, adobe::version_1::vector<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue>, adobe::version_1::capture_allocator<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue> > > const&, short, short) + 1336
    9   PublicLib.dylib                   0x0142beab CScriptDOMElement::SetSimpleAttributes(adobe::version_1::vector<KeyValuePair<IDType<Scrip tID_tag>, DOMAttributeValue>, adobe::version_1::capture_allocator<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue> > > const&, short) + 91
    10  PublicLib.dylib                   0x0142c0d3 CScriptDOMElement::SetAttributes(adobe::version_1::vector<KeyValuePair<IDType<ScriptID_ta g>, DOMAttributeValue>, adobe::version_1::capture_allocator<KeyValuePair<IDType<ScriptID_tag>, DOMAttributeValue> > > const&) + 51
    11  PublicLib.dylib                   0x0142a2ea CScriptDOMElement::SetAttribute(IDType<ScriptID_tag>, DOMAttributeValue const&) + 202
    2) That works. Moved all pages (frame threading was preserved) to a new doc, exported to IDML, opened new IDML file just fine. Woo hoo! One of my editors won't be pleased that all of the tracked changes have disappeared, but at least the file functions now
    Wish I knew what caused the problem in the first place so we could (hopefully) prevent this from happening again. Any ideas?
    Thanks again for your help!
    Cheers,
    Andrea

  • Problem with a progress bar for downloading attachment

    I display the progress bar for downloading attachments and it works fine … but when I am downloading some attachments I get the exception message:
    Exception in thread "main" com.sun.mail.util.DecodingException: BASE64Decoder: Error in encoded stream: needed 4 valid base64 characters but only got 1 before EOF, the 10 most recent characters were: "Q3w5ilxj2P"
    I found the explanation:
    Certain IMAP servers do not implement the IMAP Partial FETCH
    functionality properly. This problem typically manifests as corrupt
    email attachments when downloading large messages from the IMAP
    server. To workaround this server bug, set the
         "mail.imap.partialfetch"
    property to false. You'll have to set this property in the Properties
    object that you provide to your Session.
    http://java.sun.com/products/javamail/NOTES113.txt
    So I turned off partial fetch:
    Properties props = System.getProperties();
    props.setProperty("mail.store.protocol", "imaps");
    props.setProperty("mail.imaps.partialfetch", "false");
    Session session = Session.getDefaultInstance(props, null);
    Store store = session.getStore("imaps");
    store.connect("imap.gmail.com", "<username>","<password>");this solved the problem ….however the method getInputStream() from the Part class blocks the thread until the attachment is completely downloaded and it is impossible to get the information about the number of bytes which have been already downloaded from mailbox.
    Without this information it is impossible to display the progress bar. So is there a way to obtain this information and display the progress bar?
    Edited by: 911161 on 2012-01-31 10:55

    Try the answer I provided to your post on stackoverflow.com:
    http://stackoverflow.com/questions/9086700/how-to-displaly-progress-bar-for-downloading-attachment

  • Hi! having problem with aam program launch for downloading

    hi can you help me having problems downloading app I can't drag and drop and if I try to install using download link it tells me to choose the aam program I want to use.  I have successfully downloaded other apps before and dont know where to find this program really need some help with this. Thanks!

    Thanks
    for quick response
    I can access the aam now that I know what it stands for by opening the application seperately from the desktop and download. What I cant do is download from the cloud site where it is unable to locate and open the aam from there. As long as I can download I dont have a problem with it Im guessing it may well be a windows or browser issue. I will try from chrome if I it doesnt work I will let the firum know I would be interested to know whether its something Im doing or its a common issue.
    Cheers
    Helen

  • Travel management - problem with post a trip for an employee in India

    Hi,
    I am configure travel management for a customer, in there SAP system. I have already made the configuration for countries like Sweden, Finland, Italy, Germany etc, but when I should do it for India I can not save a trip in PR05. I have copied the configuration (schema) from Sweden to India (India has no schema in standard) and that is no problem, but when I should enter a trip and save in PR05 I have the following problem:
    1. It seems like I am in US because travelling country is per default USA (it should be India when I have linked the employee to the company code for India in transaction code PO13 and PA40). I can change the country to IN (India).
    2. When I enter an expense type and amount, the system have a tax code for USA per default (I have configured that this expense type should choose a tax code in India but the system choose one for USA). I can change it to an Indian tax code.
    3. The system also ask for a tax jurisdiction code on the row for expense type. Here I can choose 9999 as a dummy. But I have no idea why I have to specify that. I think that is typical for USA?
    4. When I have changed the country to IN, the tax code to an indian tax code and specified the jurisdiction tax code to 9999 and then save I have got the following error message:
    " Customization for 1600 j_1iindcus missing in table
    Message no. 8I303" and when I have googled on that error message I found that I should go to:
    IMG-Logistics General-Tax on Goods movement -India-Basic Settings-Maintain COmpany code settings
    but that is according to logistics and everything else in the system as purchase etc is working fine with no problem with tax jurisdiction code so I don´t guess that I should change anything there if I destroy anything else.
    5. If I change the country to IN and not register any trip expense but instead register trip segment, that the employee should have compensation for travelling with its own car and then save I have got the message that I have not maintained the currency USD/rupie which is a sign of that the systém beleives that we are in USA.
    Please help. I have no idea how to come around this.
    Best regards Lisa

    Hi again,
    In transaction code FITVFELD I have IN as default country but if I change that country to another I still have US as trip country in PR05. In that transaction code (FITVFELD) I have domestic trip, international etc (like configuration in Sweden), but when I initialize a new trip for India I can not change trip type, if there is a domestic or international. When I do the same for Sweden I can choose so I wonder if the system get the information from USA from anywhere else.
    I have also read about jurisdiction code and that is special for USA and Canada and then not for India?
    Regards Lisa

  • Problem with non-ASCII file name in content disposition header

    Hi All,
    I am facing some problems with the non-ASCII file name incase of content-disposition header. I read from the RFC 2183 that if the file name contains non-ASCII characters then the same should be encoded before sending to browser. I did the same but realized 2 problems:
    1. The name of the file is truncated in case the file name is slightly long for e.g. �����������j�b�g��������������������������.txt
    2. Also when the same file is opened in notepad, the title is showing encoded name %E6%9C%80%E4%B8%8A%E4%BD%8D.....
    Overall, I feel that the browser is not understanding or responding to the encoded header values.
    Is there any solution to this problem? I am using Microsoft IE 6.0.
    The code snippet is given below:
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
              String fileName = "�����������j�b�g��������������������������.txt";          
              fileName = URLEncoder.encode(fileName, "UTF-8");
              resp.setCharacterEncoding("UTF-8");
              resp.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
              resp.setContentType("application/download-binary");
              String s = "This is inside txt file";
              resp.getOutputStream().write(s.getBytes("UTF-8"));
              return;
         }Any help or pointer would be highly appreciated.
    Thanks and Regards,
    Ashish

    The MIME standards for non-ASCII filenames are not widely implemented.
    Many mailers use an ad hoc method for encoding filenames. JavaMail
    supports both methods, but you need to set properties, such as the
    mail.mime.encodefilename property. See the JavaMail javadocs for
    the javax.mail.internet package.

  • Problem with encoding and charset for downloading a file

    Hi guys, I have a problem and I beg for your help, I am 1000% frustrated at this point.
    I have a servlet which have to do something and give a file log to the final user. Coding the logic for that took me about 5 minutes, the problem is that the given file doesnt shows properly in notepad (Default app to open txt files). I have tried every way I have read over the internet and absolutely nothing works.
    After trying about 20 different ways fo doing this without success, this is my actual code:
    Charset def=Charset.defaultCharset();
    OutputStreamWriter out = new OutputStreamWriter(servletOutputStream,def);
    for (String registry:regList) {
    out.write(registry+"\n");
    out.close();
    the page gives the file to the user, I can download or open it, when I open it this is the result
    registry1registry2registry3registry4registry5registry6registry7...
    and I am expecting:
    registry1
    registry2
    registry3
    registry4
    registry5
    If I open it with wordpad or notepad++ the file looks fine, but I cant achieve that notepad reads it correctly. I have spent about 10 hours on this and at this point I just dont know what to do, i have tried Windows-1252, UTF-8, UTF-16, the Default one. I have tried to set this enconding on the response header with no luck. Any help will be very appreciated.
    Thanks in advance.

    >
    I have a servlet which have to do something and give a file log to the final user. Coding the logic for that took me about 5 minutes, the problem is that the given file doesnt shows properly in notepad (Default app to open txt files). I have tried every way I have read over the internet and absolutely nothing works.
    If I open it with wordpad or notepad++ the file looks fine, but I cant achieve that notepad reads it correctly. I have spent about 10 hours on this and at this point I just dont know what to do, i have tried Windows-1252, UTF-8, UTF-16, the Default one. I have tried to set this enconding on the response header with no luck. Any help will be very appreciated.
    >
    Your file likely uses *nix style line endings and use a single LF (0x0A) as the end of each line.
    Notepad doesn't recognize a single LF as the end of line; it expects CRLF (0x0D0A). The encoding isn't the issue.
    If you have to use Notepad you will need to add code to find all of the LF characters and insert a CR character in front of them.

  • Problem with OLE - Excel file saving to the desktop error occuring

    Hello,
    I am saving my excel sheet workbook created by OLE on to my local machine.
    it is downloading properly but the issue is it is generating one temp file simultaneously,
    Example : if my file name is Test it is generating test and '~$test" file.
    i am not able to close the file ...it is saying that "excel sheet is editing by other program"
    Help me out ...

    hope you are following steps to close the file and excel...
    below code is just for reference...
    1. Save the file
    CALL METHOD OF h_work_book 'SaveAs' EXPORTING #1 = i_filename .
    2. Close the excel window
    GET PROPERTY OF h_excel_application 'ActiveWindow'  = h_activewindow .
    CALL METHOD OF h_activewindow 'Close' .
    3. Free all the OLE object you have
    FREE OBJECT : h_excel_application ,
                      h_activewindow      ,
                      h_work_books        ,
                      h_work_book         ,
                      h_active_cell       .
    4. Call FM FLUSH in the end
    CALL FUNCTION 'FLUSH'.

  • Grid line problem with linked Excel files

    I am trying to import and Excel spreadsheet to InDesign, but even when I clear grid in Excel it is still imported with grid lines.  I can't figure out how to clear them off while still having the spreadsheet correctly linked. This seems like an issue with a simple solution (I hope), I just don't normally need to use Excel for anything :/
    Any ideas? thanks
    Damon

    Damon664 wrote:
    This doesn't make any sense.
    Is this grid blue? Does it disappear when you switch to Preview Mode, and doesn't it show in an exported PDF?

  • Facing problem with RFC to File scenario

    Hi Team,
    My scenario is like this:
    Iam running a report in r/3 system which would then create a file on target side.
    I am taking source message as external definition.r/3 people have created proxy on sender side(r/3 server).
    when i run the report it would then call proxy and send data to xi.
    when i run report on r/3 end it is generating succesful msg in moni.but iam file is not getting created on file server side(iam using NFS file server).
    RWB is showing status as holding.not able to tarce out the problem exactly.
    Kindly help me out.
    Regards
    Madhu

    i have gone through the link but still unble to resolve the error.
    could help me out with more solutions?
    Regards
    Madhu

  • I am Facing Problem with the WSDl File which is in the local SAP Server

    Hi All,
               Can you please give me solution of my Problem. Here i am working with the WSDl which is create from the SAP Local System. Now i want to take the wsdl file URL from the local server to my system.Here i Struck. can you please help me .
    thanks
    Siva...

    Here i Followed  Url &sap-user=XXX&sap-password=YYY to the WSDL-URL with XXX and YYY being your username and password and you will be authenticated.
    Later i Struck. Actual my requirement is I have two views i want to take a value from the first view and then return value displayed in the second view. All input/output parameters are the taken from the WSDL file. Can you please Help me.

  • Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Facing problem with the code for sending an .xls attachment via email, a field value contains leading zeros but excel automatically removes these from display i.e. (00444 with be displayed as 444).kindly guide .

    Hi Chhayank,
    the problem is not the exported xls. If you have a look inside with Notepad or something like that, you will see that your leading zeros are exported correct.Excel-settings occurs this problem, it is all about how to open the document. If you use the import-assistant you will have no problems because there are options available how to handle the different columns.
    Another solution might be to get familiar with ABAP2XLS-Project. I got in my mind, that there is a method implemented, that will help you solving this problem. But that is not a five minute job
    ~Florian

  • I am having trouble with an excel file wanting to save when no changes were made & opening as read only for the 2nd person - but allowing them to save the file.

    1) I am having trouble with an excel file wanting to save when no changes were made.  As soon as you open the file and exit.  It prompts for a save.
    All excel versions are 15.0.4701.1002.
    Using a table.
    the functions CELL, OFFSET, TODAY, INDIRECT, NOW, INFO and RAND are not being used.
    2) Same file.   2nd person is being told they are opening the file as read only - but when they are quitting excel prompts them to save the file. 
    Everything was working fine.  I started having problems with Excel, IT wiped my version out and re-installed office. 
    File is on networked server HP - Windows Server 2012 Essentials.  
    We are all on Windows 8.1 Pro.
    I really hope someone can help - the excel expert had no answer - and passed me along to here.

    I copied the whole file and started deleting worksheets one at a time and testing it by closing it and re-opening it then closing it again – to see if it wanted to save. 
    Once all the pivot tables were deleted – the problem went away. 
    I found that some of the pivot tables had automatic refresh upon open, so this caused the excel to think data had changed. 
    It is fixed now.  By clicking on one cell of the pivot table, analyze, options, data and uncheck the 3<sup>rd</sup> square down to not automatically refresh.  NOT A NETWORK ISSUE.

  • HT1933 I am facing problems with mails after update iPhone 4S/io7. I have configured yahoo mail in iPhone 4S. When I click on refresh, it shows new mail downloaded but when I go inside inbox the new mail don't show up. Can anyone help me with this iOS 7 i

    I am facing problems with mails after update iPhone 4S/io7. I have configured yahoo mail in iPhone 4S. When I click on refresh, it shows new mail downloaded but when I go inside inbox the new mail don't show up. Can anyone help me with this iOS 7 issue ?

    Hi were you able to resolve yours?
    I was very worried losing all my medical stuff on my iPad Air 2, plus i have nothing to use for the next day! So i have to try all the possible things i read on the internet!! And this worked on my part (Thank God, and thank you Google)
    Perform a hard reboot
    Hold down the Home button and Power button on your iPhone or iPad and keep holding them until you see the Apple logo. Once you do, you can let go. When your device boots back up, go ahead and check to see if the apps have started re-downloading. If they still appear to be stuck, continue on.

Maybe you are looking for