struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Laurie Harper <lau...@holoweb.net>
Subject Re: Struts, Interceptor error message customization
Date Sat, 02 Feb 2008 17:52:35 GMT
Mike J. M. wrote:
> Hello,
> 
> 
> So I am currently using Struts, including an action that has a fileUpload
> Interceptor that checks for files that are too large and certain allowable
> file types. Right now if either of these conditions are met, the system will
> throw a generic HTTP 500 error up. What I am wondering is how to customize
> this.
> 
> 
> in the docs:
> http://struts.apache.org/2.0.6/struts2-core/apidocs/org/apache/struts2/interceptor/FileUploadInterceptor.html
> 
> i found these messages that i can supposedly customize. however, the doc
> does not specify WHERE i am supposed to put these error messages at, and
> furthermore, after looking at the source code for FileUploadInterceptor, I
> found that these messages are printed to the log file, and it doesn't look
> like it prints to the actual HTML.
> 
> 
> * struts.messages.error.uploading - a general error that occurs when the
> file could not be uploaded
> 
> 
> * struts.messages.error.file.too.large - occurs when the uploaded file is
> too large
> 
> 
> * struts.messages.error.content.type.not.allowed - occurs when the uploaded
> file does not match the expected content types specified
> 
> 
> The doc says that these error messages originate from
> struts-messages.properties. I'm guessing that's in the struts.jar itself
> because I don't see it anywhere else, so am I supposed to modify that
> directly? I'm a little bit iffy about doing that.

It's not obvious from the documentation, but the message come from the 
'global message resources', which you configure via the 
struts.custom.i18n.resources property in struts.properties. The 
struts=messages.properties file mentioned is where the standard defaults 
are stored.

So, create a resource bundle containing your customized error messages, 
say my-struts-messages.properties, and place it in the classpath, then 
add a struts.custom.i18n.resources=package.name.my-struts-messaes 
property to your struts.properties configuration.

> So, in a nutshell, how do I catch an Interceptor error and make it redirect
> to a nice page instead of the generic HTTP 500 page? Actually, what would be
> better is to redirect to an action while passing into it a parameter
> "message" that will contain error messages. Then, in the JSP i want to do
> <s:property ...> to grab that message.

I'm not sure about this part. I would expect, assuming you implement 
ValidationAware (e.g. by extending from ActionSupport), that you would 
get a validation failure rather than a status 500 response. If you're 
still experiencing that, post the corresponding error logs and stack trace.

L.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message