简体   繁体   English

我希望避免在清除屏幕时出现文件过大的错误

[英]I want to avoid a file too large error when I clear the screen

  • I have a page with a file upload option using 我有一个使用文件上传选项的页面

     <input type="file" name="fileUpload" /> 

    and it works fine. 而且效果很好。

  • I also have a Clear button on the screen which calls a method to reset all of the page fields to their default values. 我在屏幕上还有一个“ 清除”按钮,该按钮调用一种方法来将所有页面字段重置为其默认值。

  • I use @SkipValidation with the clear() method so you don't get error messages if you clear a page with invalid data. 我将@SkipValidationclear()方法一起使用,因此,如果清除包含无效数据的页面,则不会收到错误消息。

My problem is: 我的问题是:

if I click to upload a file which is too large and then click the Clear button, I get the "File too large" message , because that is generated by the default-stack (at least that is my understanding) and not by my validation code. 如果我单击上传一个太大的文件,然后单击“ 清除”按钮,则会收到"File too large"消息 ,因为该消息是由默认堆栈(至少是我的理解)而不是由我的验证生成的码。

I use document.getElementById('commentAction').reset(); 我使用document.getElementById('commentAction').reset(); in the method but that doesn't help. 在方法中,但这无济于事。

How can I reset the page without any error message ? 如何重置页面而没有任何错误消息?

UDATE Based on the suggestions I received I am using the following jquery. UDATE根据我收到的建议,我正在使用以下jquery。

function clearForm()
{
    $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
    $(':checkbox, :radio').prop('checked', false);
}

along with the following struts2 for the Clear button 以及用于清除按钮的以下struts2

            <s:submit key="button.clear" cssClass="submit" onclick="clearDirtyFlag(); clearForm(); return false"  tabindex="18"/>

It now clears the input fields without leaving the page but I have a list on the page which is generated by the following struts2 code 现在,它清除输入字段而不离开页面,但是页面上有一个由以下struts2代码生成的列表

                <s:iterator value="commentViewList" >
                <div class="row rowaltcolor">
                    <div>
                        <s:url var="commentLink" action="commentAction" method="getCommentDetails">
                            <s:param name="commentId"><s:property value="commentInfo.commentId"/></s:param>
                        </s:url>
                        <div class="col-sm-1 col-xs-12 text-left"><s:a href="%{commentLink}"  tabindex="18"><s:property value="commentTypeCode"/></s:a></div>
                        <div class="col-sm-2 col-xs-12 text-left"><s:property value="commentInfo.name"/></div>  
                        <div class="col-sm-2 col-xs-12 text-left"><s:property value="commentInfo.organization"/></div>  
                </div>
            </s:iterator> 

This list does not get cleared because it isn't a field in the generated html. 此列表不会清除,因为它不是生成的html中的字段。 The list values are hardcoded in the html when I look at the source html. 当我查看源html时,列表值被硬编码在html中。 Can I clear the list on the client side or do I need to do that on the server side and re-display the page? 我可以在客户端清除列表还是在服务器端清除列表并重新显示页面? Thanks! 谢谢!

For anyone who is googling I thought I should put what solved the problem for me in an answer. 对于那些正在使用谷歌搜索功能的人,我认为我应该把解决问题的方法放在我的答案中。 Using 运用

function clearForm()
{
     $(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
     $(':checkbox, :radio').prop('checked', false);
}

cleared all of the input fields (including hidden fields) without going to the action. 清除所有输入字段(包括隐藏字段),而无需执行操作。 I still used a <s:submit> tag but I used return false to keep the page from being submitted as follows. 我仍然使用<s:submit>标记,但是我使用return false来阻止页面提交,如下所示。

<s:submit key="button.clear" cssClass="submit" 
          onclick="clearForm(); clearDirtyFlag(); return false"  tabindex="18" />

For my page that didn't work because I had a list generated by struts on the page I needed to clear so I had to go ahead and call my action and render the page again. 对于我的页面不起作用,因为我需要清除页面上由struts生成的列表,因此我必须继续调用我的操作并再次呈现该页面。 So my final submit code was 所以我最后的提交代码是

<s:submit method="reset" key="button.clear" cssClass="submit" 
          onclick="clearForm(); clearDirtyFlag();"  tabindex="18" />

暂无
暂无

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

相关问题 在内存有限的系统上写入大文件时,如何避免mapFailed()错误 - How do I avoid mapFailed() error when writing to large file on system with limited memory 我如何声明一个大字符串( <Html> 代码)中避免“常量字符串过长”的错误? - How can I declare a Large String(<Html> codes) in Java to avoid “Constant string too long” error? 如果XML文件太大,如何终止请求? - How can I abort a request if the XML file is too large? 为什么我在没有文件的情况下收到请求实体太大? - Why am I getting Request Entity Too Large WITHOUT file? 如何解决Java Applet的代码太大错误? - How Do I Fix a Code Too Large Error for a Java Applet? 当我做大循环时,应用程序花费太多RAM - App spends too much RAM when I do large loops 我想使用 NetBeans IDE 6.9.1 清除 Java 中的输出屏幕 - I want to clear my output screen in Java using NetBeans IDE 6.9.1 当我编译此代码时,会出现错误,例如整数数太大。 尽管我声明了很长时间,但我不知道为什么它显示错误? - when I compile this code I get error like Integer number too large. Though I declare it as long, I don't know why it is showing error? 我想读写文件,运行时出现此错误:java.io.EOFException - I want to write and read from a file and I have this error when I run : java.io.EOFException 我想避免在我的jsp页面上使用scriptlet。 我有谷歌搜索并在这里搜索,但我无法解决它 - i want to avoid scriptlets on my jsp pages. I have google it and search here too but i was not able to solve it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM