Solved

setHeader method in JAVA

Posted on 2000-02-18
5
347 Views
Last Modified: 2012-08-13
How can I add the size of the file to my headers so that people downloading my .rtf files will know how large the files are?

the following code is what I have so far:

setHeader("Content-disposition", "attachment;filename=" + reportType + ".rtf");

is adding  ";filesize=" + filename.size() even close to an answer?

0
Comment
Question by:jerelw
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
mbormann earned 100 total points
ID: 2536636
I think it's Content-Length, I think that before you write anything to the stream,set it with the correct Length you are going to write.

Note that thsi is the way of specifying persistemt connections (also called as Keep Alive)

Read for basics
http://www-4.ibm.com/software/webservers/appserv/doc/v20dcadv/doc/readme.txt

code
http://www.servletforum.com/sf/1999/Nov/941724512594.html
0
 
LVL 3

Author Comment

by:jerelw
ID: 2538553
i'll try it, for a bonus, how do i get the file size if the report is created at runtime?
0
 
LVL 5

Expert Comment

by:mbormann
ID: 2541249
was away on leave ,but the file size is always got at runtime.I don't understand what you mean to say.
0
 
LVL 3

Author Comment

by:jerelw
ID: 2542445
is there a method called getSize() that would return an int of my file in bytes?

for example,

File f = new File("myFile");
int size = f.getSize();

and then in my header I can specify my file size by entering:

content-length: size }
0
 
LVL 5

Expert Comment

by:mbormann
ID: 2542480
int size = (int)f.length();
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 109
Cipher Configuration on Apache HTTPD 4 63
How to monitor the number of connections/threads being utilized on Tomcat 6.0 8 71
use lov values 2 51
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question