javascript - 在 JSP 中使用 HTML type=file 上传文件,并在上传之前在 javascript 中执行一些检查...

标签 javascript html jsp

目前我们有这个代码来上传文件

<input id='fileBrowse' type='file' style="width:187px;height:20px" class='fileBrowse' onchange="onBrowseFile( this );" />

执行一些检查的 javascript 函数如下:

    function onBrowseFile( fb ) {
    var myFSO = new ActiveXObject("Scripting.FileSystemObject");
    var thefile = myFSO.getFile(fb.value);
    if( (thefile.size / 1000000) > maxfilesize) {
        alert( "The size of the files you have tried to drag and drop exceed the maximum allowed. Please drag no more than "+maxfilesize+" MB at a time." );
        return;
    }
    if( fb.value.indexOf( ".exe" ) > -1 ||
            fb.value.indexOf( ".asp" ) > -1 ||
            fb.value.indexOf( ".aspx" ) > -1 ||
            fb.value.indexOf( ".cab" ) > -1 ||
            fb.value.indexOf( ".com" ) > -1 ||
            fb.value.indexOf( ".dll" ) > -1 ||
            fb.value.indexOf( ".java" ) > -1) {
        alert( "The import of one or more files type are not permitted" );
        return;
    }
    document.getElementById( "txtFilePath" ).value = fb.value;
}

现在的问题是我们现在使用 IE9,而 IE9 安全性不允许我们在不修改安全设置或注册表的情况下使用 ActivexControl。我们无法这样做,因为我们有 5000 个该应用程序的用户。

请建议我们还可以使用什么来解决这个问题。我们必须进行这些检查...

最佳答案

您可以在服务器端运行检查。

关于javascript - 在 JSP 中使用 HTML type=file 上传文件,并在上传之前在 javascript 中执行一些检查...,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10120278/

相关文章:

javascript - 我可以使用哪种 javascript 或 JQuery 图表工具来创建带有垂直列标签的热图图表?

javascript - 如何让我的网站检测到某些 Web 浏览器?

javascript - window.history.replaceState 中的 'data' 是什么

php - 选择表中与相关表及其字段用户名和密码相匹配的行

java - 如何将从 JSP 请求的 XML 数据格式化为表

javascript - 有没有等同于 Ruby 的 Object#tap 的 jQuery?

javascript - AngularJS 指令 : "templateUrl" doesn't work while "template" works

javascript - 限制 Mustache.js 标签呈现的字符数

java - 内部 Servlet 映射 - web.xml

java - 表达式语言将 "-"符号视为字符串文字而不是减号运算符?