How does servlet work?

I'm curious about how does a request interacts with a servlet. Here's my understanding, pls correct me if I'm wrong.

A Java Request object consists of a http header as well as parameters that are passed. These parameters maybe textual input fields or even a whole file, etc. Once the web server recieved the whole request, it transforms the request into a Java Request object and invoke the corresponding servlet and passes to the service() to handle it.

Here come my questions. does the http request come once as a whole? or only the header of the request is first passed to the server, leaving other parameters and maybe the file for uploading being sent later? If so, when will the servlet be invoked? Once it received the header, or after it has received the whole http request?

As the service() as well as the doGet() and doPost() accepts a request object, it seems that there's no way to add handling of the http request based on the context of the http header. All I'm working is to write a servlet that accepts file uploading and my code is referenced from O'Reilly's Multipart code source. I want to reject the upload of a file if its' size exceeds a limit when I read the content length in the header. Is it possible for servlet to reject the upload of a file based on the header? Or it's solely the implementation of the webserver?

Pls help.

[1400 byte] By [slho7] at [2007-9-26 2:44:41]
# 1

Hello!

I'm working with WebSphere Application Server and I developed project where big files uploading was needed.

File data is transfered to the servlet via ServletInputStream object. File is set of special formatted records and if some record has invalid format (for example invalid digital signature) whole file must

be rejected. I terminate execution of doPost method if

errors were found. Only part of file data was transfered to

the servlet in that case. But there is some caching (I think web server transmit data to application server in blocks of fixed length) and some part of data was transfered via HTTP-connection that exceed total size of correct records.

But I think that implementation of such technique is application server depended.

Nikolay Stanchenko,

JSC TKK

n.stanchenko@transcredit.ru

nick_st at 2007-6-29 10:25:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Your mention that you are using O'Reileys Multipart class. You can actually use the multipart constructor with the following signature:

MultipartParser mp = new MultipartParser( HttpServletRequest request, int MAX_CONTENT_SIZE);

Keep in mind that MAX_CONTENT_SIZE is the maximum size of the entire content (body) of the request. Thus if you are posting parameters in addition to the attachment those will count towards the content size. In this case you will need to manually read the bytes from the FilePart class and perform limit checking.

steveEbersole at 2007-6-29 10:25:20 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...