views:

121

answers:

2

Is there analog of PHP "MAX_FILE_SIZE" parameter for JSP?

It's needed to perform validation on UI before upload process triggered on backend.

+2  A: 

The setSizeMax() method in Apache Commons FileUpload's ServletFileUpload class lets you set the maximum size to accept in the request. If the request body is larger than the max, it will throw a SizeLimitExceededException. Details at http://commons.apache.org/fileupload/.

Brian Showalter
+1  A: 

That depends on the servletcontainer in question, not on JSP. As you didn't mention which one you're using, I'll only take Apache Tomcat as an example.

It's technically actually the maximum size of the request body. The request body is the one which is been filled POST requests. It is often only exceedingly large when it's used to upload file(s). In Tomcat the maximum size is configureable as maxPostSize attribute of the <Connector> element in /conf/server.xml which defaults to 2MB. Here's an example with 2MB:

<Connector maxPostSize="2097152">

You can find more details in this this Tomcat-specific document. If you're using a different make, you'll need to consult its documentation, but you now at least know where to look and on which keywords.

BalusC
yes, this is Tomcat. I need provide property on UI where user points max size. seems,that server.xml isn't for this case.thanks any way
sergionni
You was literally asking for equivalent of PHP `MAX_FILE_SIZE`. If you want to control the size on request-basis and throw exceptions accordingly, then to the point just count the bytes which are been streamed in :) If you're -as everyone- using Apache Commons FileUpload to handle file uploads, then you can just configure it in its settings. Also see the *User Guide* and *Frequently Asked Questions* sections at their homepage http://commons.apache.org/fileupload
BalusC
i use Apache Commons FileUpload. i asked about UI part,before POST processed.ok, i will read doc ) the topic became more claer and clear
sergionni