我有一个应用程序,可以让你上传一些照片。我有一个jsp页面与表单选择要上传的照片是什么:为什么jF中没有显示(正确)错误“file.too.large”?
苏比尔-foto.jsp
...
<s:form action="SubirFoto" method="post" enctype="multipart/form-data" theme="bootstrap">
<s:file name="foto" label="Foto" />
<s:submit value="Upload" align="center" />
</s:form>
...
我想,随着这种形式下,用户只能上传特定类型的文件(如jpg,gif ...),并且不要让用户上传大小超过2 MB的照片。
struts.xml的
<action
name="SubirFoto"
class="impl.redex.presentation.profile.upload.SubirFotosAction">
<interceptor-ref name="fileUpload">
<param name="maximumSize">2097152</param>
<param name="allowedTypes">
image/png,image/gif,image/jpeg,image/pjpeg
</param>
</interceptor-ref>
<interceptor-ref name="dentroStack"></interceptor-ref>
<result name="success">/WEB-INF/jsps/foto/foto-subida.jsp</result>
<result name="input">/WEB-INF/jsps/foto/subir-foto.jsp</result>
</action>
的文件上传的作品完美,除了一两件事。如果满足要求,我可以上传任何照片。如果我尝试上传不是照片的文件(例如,纯文本文件),应用程序会将我在global.properties
中定义的错误输入到jsp表单的输入中。
global.properties
struts.messages.error.uploading - No se ha podido subir el fichero
struts.messages.error.file.too.large - El fichero es demasiado grande. El tamaño máximo es de 2MB.
struts.messages.error.content.type.not.allowed - Tipo de fichero no aceptado. Sólo es válido si la foto \
está en formato jpg/jpeg, gif o png.
的问题就来了,如果我尝试比2 MB上传图片越大,应用重定向我苏比尔-foto.jsp,但它不把任何错误在jsp页面中。
我已经尝试了一下,如果我把<s:actionerror />
苏比尔-foto.jsp的时候我上传的照片大就出现这样的:
the request was rejected because its size (17224595) exceeds the configured maximum (2097152)
正如你所看到的,这不是错误,我已在global.properties
中定义。
为什么这两个不同的错误现场错误?这是引导插件的问题吗?或者它是Struts2的错误?难道我做错了什么?任何帮助表示赞赏,谢谢。
是否将global.properties注册为自定义i18n资源?例如,在你的struts.xml(或struts.properties)中:' '? –
是的,我有我的struts.xml行'<常数 \t \t NAME = “struts.custom.i18n.resources” \t \t值= “全球”/>' – Pigueiras