That code streams something from a servlet, so I guess the answer to my question is "no, I do not use a component to display an Excel sheet".
The servlet API doesn't know the first thing about the contents of what it streams; you need to check the API of whichever library you're using to create the file.
the first if block checks if the file name ends with 'PDF then the output(i.e the report contents will be shown in PDF format or else if it is not ending with
the .PDF,then the output will be shown in excel sheet.
so i think i need to do something in else statement only.
I don't know what the "the report contents" are, but you seem to assume that the servlet emits certain file types according to the content type you set. That is not the case; all that header does is tell the client "this is PDF" or "this is XLS". If the content that then gets streamed is not actually in that format, then there will be problems.
So: What format is the content in? How is it created?