0

fileUpload我正在尝试使用拦截器对上传到我的网站的文件施加限制。验证失败后,我稍后会在我的validate()方法中收到空指针异常。我目前有这样的拦截器struts.xml

<interceptor-ref name="basicStack"/>
<interceptor-ref name="fileUpload">
    <param name="maximumSize">1048576</param>
</interceptor-ref> 
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>

我发现这可能与fileUpload验证之前的到来有关。我知道它需要按这个顺序发生,但是如果fileUpload失败,那么我就不会从我的表单中获取其他输入的数据;这些字段都是空的。

我试图在验证失败后将用户带回表单,并且在验证失败后,他们输入的其余数据已经填充回表单中。一旦上传失败,我将如何让请求继续而不是停止?

例外:

Struts Problem Report

Struts has detected an unhandled exception:

Messages:   
File:   profiles/actions/UpdateProfileAction.java
Line number:    183
Stacktraces

java.lang.NullPointerException
profiles.actions.UpdateProfileAction.validate(UpdateProfileAction.java:183)
   com.opensymphony.xwork2.validator.ValidationInterceptor.doBeforeInvocation(ValidationInterceptor.java:251)
com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
etc.

这将我们指向动作验证方法:

profile.setAvailabilityLength(Jsoup.clean(availabilityLength.trim(), Whitelist.basic()));

我们不检查是否availabilityLength == null. 检查将解决问题,但表单将重新填充空数据,而不是用户输入的内容。

4

0 回答 0