Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

problem faced while using setContentType("Application/csv")

Thread view: 
Madni - 02 Jan 2006 12:16 GMT
Hi.

while i am trying to respond my client with the dilaog using which a
client user could save the file , the file which is to be sent from
server .... i am facing some issues in
setContentType("Application/csv") .... (file type is csv) ... here is
the chunk of code ....

System.out.println("This line gets displayed before setting content
type");
  httpservletresponse.setContentType("application/csv");
  System.out.println("After setting content type") // This line never
gets displayed
 httpservletresponse.setHeader("Content-Disposition","inline;
filename=" +strtemp[1]+".csv" );

                          try {
                            File uFile = new File(strFilePath);
                            int fSize = (int) uFile.length();
                            FileInputStream fis = new
FileInputStream(uFile);
                            PrintWriter pw =
httpservletresponse.getWriter();
                            int c = -1;
                            while ( (c = fis.read()) != -1) {
                              pw.print( (char) c);
                            }
                // Close output and input resources.
                            fis.close();
                            pw.flush();
                            pw = null;
                          }
                          catch (Exception e) {
                               System.out.println("Exception is caught
");
                               e.printStackTrace();

Any suggestion regarding the issue will be highly obliged ...

Regards,
Madni
Chris Smith - 04 Jan 2006 04:25 GMT
> while i am trying to respond my client with the dilaog using which a
> client user could save the file , the file which is to be sent from
[quoted text clipped - 7 lines]
>    System.out.println("After setting content type") // This line never
> gets displayed

Sounds like you've committed the response already.  What happens to any
exceptions thrown from setContentType?  If there are any, what are they?  
If you're swallowing them silently, what are they after you stop
swallowing them?  What are you doing to the response before this line?

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

josh.s17@gmail.com - 04 Jan 2006 10:34 GMT
This is only a lunch but I think your problem might because you are
using a printwriter to send the response.

Try using an output stream instead eg

   OutputStream out = httpservletresponse.getOutputStream;


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.