I am generating a report using jsp. To get the output in excel.
If you are using requestdispatcher.include() to get to your JSP, then the outputstream/writer is getting flushed before the JSP runs. This means you cannot change the headers, and hence, cannot change the content type. You can change the header by forwarding the request from the servlet to your JSP. You must be sure that you do not write anything to the outputstream or writer before you forward, or the forward will fail.