简体   繁体   English

Struts2要求用户上传文件验证

[英]Struts2 Require the user to upload a file validation

I am uploading a file to my Server using Struts2 file upload, my question is that how do I specifically tell that the it is a requirement to upload a file? 我正在使用Struts2文件上传将文件上传到我的服务器,我的问题是我如何特别告诉我这是上传文件的要求? here is my interceptor. 这是我的拦截器。

<action name="audioupload" class="actions.AudioUploadAction"
        method="execute">
        <interceptor-ref name="basicStack" />
        <interceptor-ref name="fileUpload">
            <param name="allowedTypes">text/html</param>
        </interceptor-ref>
        <interceptor-ref name="validation" />
        <interceptor-ref name="workflow" />
        <result name="input">/UploadAudio.jsp</result>
        <result name="success">/UploadSuccess.jsp</result>
    </action>

How do I specifically tell that the user is required to upload a file? 我如何明确告诉用户必须上传文件?

What you can do is create a ActionClass-validation.xml and inside that you'll declare it here. 您可以做的是创建一个ActionClass-validation.xml,然后在其中声明它。

<validators>
    <field name="theNameOfTheFileTag">
        <field-validator type="required">
            <message>File is required.</message>
        </field-validator>
    </field>
</validators>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM