<bdo id='J6I8R'></bdo><ul id='J6I8R'></ul>
<i id='J6I8R'><tr id='J6I8R'><dt id='J6I8R'><q id='J6I8R'><span id='J6I8R'><b id='J6I8R'><form id='J6I8R'><ins id='J6I8R'></ins><ul id='J6I8R'></ul><sub id='J6I8R'></sub></form><legend id='J6I8R'></legend><bdo id='J6I8R'><pre id='J6I8R'><center id='J6I8R'></center></pre></bdo></b><th id='J6I8R'></th></span></q></dt></tr></i><div id='J6I8R'><tfoot id='J6I8R'></tfoot><dl id='J6I8R'><fieldset id='J6I8R'></fieldset></dl></div>

  • <legend id='J6I8R'><style id='J6I8R'><dir id='J6I8R'><q id='J6I8R'></q></dir></style></legend>
  • <tfoot id='J6I8R'></tfoot>
  • <small id='J6I8R'></small><noframes id='J6I8R'>

      1. 如何在 Struts 2 中验证文件上传

        How to validate file upload in Struts 2(如何在 Struts 2 中验证文件上传)

            <tbody id='XFxq8'></tbody>
          • <small id='XFxq8'></small><noframes id='XFxq8'>

            • <legend id='XFxq8'><style id='XFxq8'><dir id='XFxq8'><q id='XFxq8'></q></dir></style></legend>

            • <i id='XFxq8'><tr id='XFxq8'><dt id='XFxq8'><q id='XFxq8'><span id='XFxq8'><b id='XFxq8'><form id='XFxq8'><ins id='XFxq8'></ins><ul id='XFxq8'></ul><sub id='XFxq8'></sub></form><legend id='XFxq8'></legend><bdo id='XFxq8'><pre id='XFxq8'><center id='XFxq8'></center></pre></bdo></b><th id='XFxq8'></th></span></q></dt></tr></i><div id='XFxq8'><tfoot id='XFxq8'></tfoot><dl id='XFxq8'><fieldset id='XFxq8'></fieldset></dl></div>
                <tfoot id='XFxq8'></tfoot>
                  <bdo id='XFxq8'></bdo><ul id='XFxq8'></ul>
                  本文介绍了如何在 Struts 2 中验证文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  上传videoAction.java

                  private File id;
                  private String title;
                  private String url;
                  private String name="";
                  private String message="";
                  private String idContentType;  
                  private String idFileName;
                  
                  public String getIdContentType() {  
                      return idContentType;  
                  }  
                  
                  public void setIdContentType(String idContentType) {  
                      this.idContentType = idContentType;  
                  }  
                  public String getIdFileName() {  
                      return idFileName;  
                  }  
                  public void setIdFileName(String idFileName) {  
                      this.idFileName = idFileName;  
                  }  
                  public void setServletRequest(HttpServletRequest servletRequest) {  
                      this.servletRequest = servletRequest;  
                  
                  }
                  public String getMessage() {
                      return message;
                  }
                  public void setMessage(String message1) {
                      this.message = message;
                  }
                  public String getName() {
                      return name;
                  }
                  public void setName(String name) {
                      this.name = name;
                  }
                  public File getId() {
                      return id;
                  }
                  public void setId(File id) {
                      this.id = id;
                  }
                  public String getTitle() {
                      return title;
                  }
                  public void setTitle(String title) {
                      this.title = title;
                  }
                  public String getUrl() {
                      return url;
                  }
                  public void setUrl(String url) {
                      this.url = url;
                  }
                  

                  struts.xml:

                  <action name="uploadvideo" class="com.myapp.ysrcptv.UploadvideoAction">
                      <interceptor-ref name="fileUpload">   
                          <param name="allowedTypes">video/mp4,video/ogg,video/webm</param>  
                      </interceptor-ref>  
                      <interceptor-ref name="defaultStack"></interceptor-ref>  
                  
                      <result>${url}</result>
                      <result name="login">adminlogin.jsp</result>
                      <result name="input">${url}</result>
                  </action>
                  

                  上传视频.jsp:

                  <s:form cssClass="form" action="uploadvideo" method="post" validate="false" enctype="multipart/form-data">
                  <s:file cssClass="input" name="id" value="" placeholder="Video"></s:file>
                  <s:textfield cssClass="input" name="title" value="" placeholder="Video Title"></s:textfield>
                  <input type="hidden" name="name" value="gellery pic"/>
                  <input type="hidden" name="url" value="uploadvideos.jsp"/>
                  <s:submit cssClass="btn" value="Upload"></s:submit>
                  <div class="formdiv"><s:property value="message"/></div>
                  </s:form>
                  

                  上传videoAction-validation.xml:

                  <!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
                          "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd">
                  <validators>
                  
                     <field name="id">
                          <field-validator type="requiredstring">            
                              <message>File is required.</message>
                          </field-validator>
                      </field>
                  


                  问题:只有服务器端文件 id 验证不起作用.即使我选择了一个文件,它也会显示验证消息 File is required.其余验证工作正常.这里我放一些东西.在它工作之前.重新启动我的服务器后,此验证不起作用.


                  Problem: Only server side file id validation is not working. Even if I selects a file its also showing validation message File is required. Remaining validations are working perfectly. Here I'm placing some stuff. Before its worked. After restarting my server this validation not working.

                  推荐答案

                  你使用了错误的验证器."requiredstring" 验证器用于验证文本字段.您可以使用 "required" 验证器来验证字段是否为 null.

                  You have used wrong validator. "requiredstring" validator is used to validate textfields. You can use "required" validator that validates the field to be not null.

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

                  这篇关于如何在 Struts 2 中验证文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                  <legend id='iwcPO'><style id='iwcPO'><dir id='iwcPO'><q id='iwcPO'></q></dir></style></legend>

                  • <small id='iwcPO'></small><noframes id='iwcPO'>

                    <i id='iwcPO'><tr id='iwcPO'><dt id='iwcPO'><q id='iwcPO'><span id='iwcPO'><b id='iwcPO'><form id='iwcPO'><ins id='iwcPO'></ins><ul id='iwcPO'></ul><sub id='iwcPO'></sub></form><legend id='iwcPO'></legend><bdo id='iwcPO'><pre id='iwcPO'><center id='iwcPO'></center></pre></bdo></b><th id='iwcPO'></th></span></q></dt></tr></i><div id='iwcPO'><tfoot id='iwcPO'></tfoot><dl id='iwcPO'><fieldset id='iwcPO'></fieldset></dl></div>
                      <tbody id='iwcPO'></tbody>
                        • <bdo id='iwcPO'></bdo><ul id='iwcPO'></ul>

                          <tfoot id='iwcPO'></tfoot>