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 / August 2007

Tip: Looking for answers? Try searching our database.

download servlet

Thread view: 
finecur - 22 Aug 2007 19:22 GMT
Hi,

I am writing a servlet which output some text. When user call this
servlet, it display the content of the text in the web browser. But
this is not what I want. What I really want is once user call this
servlet, a window popup with options of "Open", "Save", and "Cancel",
just like you download someting from the web.

How can I do it?

Thanks,

ff
Manish Pandit - 22 Aug 2007 19:44 GMT
> Hi,
>
[quoted text clipped - 9 lines]
>
> ff

Assuming what you want is sending a text file instead of rendering
markup on the browser, then look at writing on the response, and
setting response headers and type.

Something like:

response.setContentType("text/plain");
response.setHeader("Content-Disposition","attachment; filename=" +
yourFileName);
response.getWriter().write(textContent);

-cheers,
Manish
finecur - 23 Aug 2007 00:22 GMT
> > Hi,
>
[quoted text clipped - 23 lines]
> -cheers,
> Manish

Thanks, it worked very well. I found, however, if I added:

       response.setHeader("Cache-Control","no-cache");
       response.setHeader("Pragma","no-cache");

it would not work. Do you know why?

Thanks,

ff


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



©2009 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.