|
You can add character encoding to fool the browser. For example the
following would force browser to display save screen instead of displaying
the pdf using Acrobat:
HttpServletResponse.setContentType("application/pdf;charset=UTF-8")
(This was not tested on all browsers.)
Thanks.
----- Original Message -----
From: "Art Smet" <smet@xxxxxxxxxx>
To: "Java Programming on and around the iSeries / AS400"
<java400-l@xxxxxxxxxxxx>
Sent: Wednesday, March 19, 2003 5:53 PM
Subject: Re: Servlet and text/plain
>
>
>
>
> I know the following will force a Save dialog at the browser, I think it
is
> the resp.setContentType( ) that really does the trick. You can use the
> following code as a basis, and extract what you need to pull off the Save
> dialog for your code.
>
> import java.io.*;
> import java.net.*;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import com.oroinc.text.perl.*;
>
> public class BigDownloadTest extends HttpServlet {
> public void doGet( HttpServletRequest req, HttpServletResponse
resp )
> throws ServletException, IOException {
>
> long bytes = Long.parseLong(req.getParameter("bytes"));
> File tempFile = File.createTempFile("download", ".zip");
>
>
> //no filename specified, so lets fashion something as long as
> the bytes they specified.
> java.io.FileOutputStream fos = new
> java.io.FileOutputStream(tempFile);
> byte [] array = {'9','8','7','6','5','4','3','2'};
> long l;
> for(l = 0; l < bytes-8; l+=8){
> fos.write(array);
> }
> fos.write(array,0,(int)(bytes-l));
>
> String type =
> getServletContext().getMimeType(tempFile.getAbsolutePath());
> if (type != null)
> {
> resp.setContentType(type);
> }
>
> resp.setDateHeader("last-modified", tempFile.lastModified());
> resp.setContentLength(new Long(tempFile.length()).intValue());
>
> FileInputStream in = new FileInputStream(tempFile);
> try
> {
> ServletOutputStream out = resp.getOutputStream();
> byte[] buf = new byte[4096];
> int numRead = in.read(buf);
> while (numRead != -1)
> {
> out.write(buf, 0, numRead);
> numRead = in.read(buf);
> }
> } finally {
> in.close();
> }
> }
> }
>
>
>
>
>
> |---------+------------------------------>
> | | "Mark Phippard" |
> | | <MarkP@xxxxxxxxxxxx|
> | | com> |
> | | Sent by: |
> | | java400-l-bounces@x|
> | | idrange.com |
> | | |
> | | |
> | | 03/19/2003 07:30 PM|
> | | Please respond to |
> | | Java Programming on|
> | | and around the |
> | | iSeries / AS400 |
> | | |
> |---------+------------------------------>
>
>---------------------------------------------------------------------------
----------------------------------|
> |
|
> | To: Java Programming on and around the iSeries / AS400
<java400-l@xxxxxxxxxxxx> |
> | cc:
|
> | Subject: Re: Servlet and text/plain
|
> |
|
>
>---------------------------------------------------------------------------
----------------------------------|
>
>
>
>
>
> Larry,
>
> If you find a way that is 100% I'd love to know. We cannot find a way
even
> when sending something like a PDF. We have searched a lot of web forums
to
> know avail. The best you can do is give the browser some "hints" in the
> headers. There is one where you give it the filename you want to use, I
> think another where you say it is an attachment, and of course there is
the
> mime type.
>
> In general, we have found that if IE feels it can handle the type, it will
> regardless of what you say. Netscape/Mozilla will generally do what you
> want.
>
> Good luck.
>
> Mark
>
>
>
>
> To: java400-l@xxxxxxxxxxxx
> cc:
> bcc:
> Subject: Servlet and text/plain
> "Larry" <larryhytail@xxxxxxxxx>
> Sent by: java400-l-bounces@xxxxxxxxxxxx
> 03/19/2003 11:26 AM
> Please respond to Java Programming on and around the iSeries / AS400
> <font size=-1></font>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Here's what I think should be a simple question, but I could not find the
> answer.
> I have a servlet that generates dynamic content in text/plain format that
> the end user really does not want to display in his/her browser, but
really
> wants to accept it as a download file. If you click on my link to the
> servlet, currently it builds the data and displays it in text in the
> browser.
> Of course the user could right click and do "save file as" to stream it
> directly to a file on his/her hard drive, but that is not elegant. How do
I
> make the servlet automatically bring up the save file dialog?
> Thanks,
> Larry
>
> _______________________________________________
> No banners. No pop-ups. No kidding.
> Introducing My Way - http://www.myway.com
>
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.