Here is a portion of my struts.xml:
<constant name="struts.custom.i18n.resources" value="global" />
and
<action name="picture_save" method="pictureSave" class="PictureActionBean">
<interceptor-ref name="fileUpload">
<param name="maximumSize">
2097152
</param>
<param name="allowedTypes">
image/bmp,image/gif,image/jpeg,image/jpg,image/png
</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success" type="redirect">picture</result>
<result name="error">error</result>
</action>
My global.properties file is stored directly in src/ and it contains this:
struts.messages.error.uploading=Upload failed
struts.messages.error.file.too.large=Upload file is too large
struts.messages.error.content.type.not.allowed=Wrong file type uploaded
Here is how I'm displaying the error in the jsp:
<s:fielderror />
Currently, when I upload a file that is too big for example, I get the error:
the request was rejected because its size (6561343) exceeds the configured maximum (2097152)
What I want to do is make it say "Uploaded file is too large" instead of the message above. What is an easy way to do this?
EDIT 1:
I'm using struts version 2.1.8.1
EDIT 2:
Another thing is that when I add:
<result name="input" type="redirect">error</result>
to my struts.xml then no error shows at all. What is the reason for this?
Source Overriding Struts Default Properties
Source MessageStoreInterceptor
Note: I'm here pointing to older version of struts so if you were using latest version change the version in url.
hehe, you rly sticked on this question. it seems pretty simple.
Check out the example here: http://struts2-by-ash.blogspot.com/2012/06/override-struts-2-messages.html
best, j
Use
<s:actionerror />
tag in JSP to print the error.Firstly, This error comes into picture if you are trying to upload a file more than the file size you specified for struts.multipart.maxSize
There's a pretty easy solution: In your struts.xml, increase the file size value of struts.multipart.maxSize,
Keep param name="maximumSize" value less than struts.multipart.maxSize value, As in above case, you will get your customised error defined in global.properties unless you exceed struts.multipart.maxSize limit..so try to keep struts.multipart.maxSize value to some high range.