struts2整合uploadify插件怎样传参数

关于uploadify3.1,先看下帮助文档中的有些知识。

其中有个onUploadStart方法,我们可以使用这个向后台传参。

下面举个例子,

js:

<script type="text/javascript">
    $(function () {
        $('#actpic').uploadify({
            'debug': false,
            'auto': false,
            'multi': true,
            'uploader': 'admin/uploadyear.action',
            'fileObjName': 'actpic',
            'removeCompleted': false,
            'progressData': 'percentage',
            'buttonText': '附件上传',
            'formData':{'getyearid':${getyearid},'statisform_obj_id':${getyearid?default(0)},'statistical_form_name3':'1','remark_name':'1','other_tagsname':'1','idStr':'1'},

            'method': 'post',
            'cancel': 'uploadify/uploadify-cancel.png',

            'fileSizeLimit': '50MB',
            'swf': 'uploadify/uploadify.swf',
            'width': 300,
             'onUploadStart':function(file){
                //获取数据
                var statistical_form_name3 = $("#statistical_form_name3").val();
                var other_tagsname = $("#other_tagsname").val();
                var remark_name = $("#remark_name").val();
                alert(statistical_form_name3);
                alert(other_tagsname);
                alert(remark_name);
                // 以下是得到选中的复选框
                var ids = new Array();
                if ($("input[name='tagsname']:checked").size() == 0) {
                    alert("请选择需要检索的标签!");
                    return false;
                }
                $("input[name='tagsname']:checked").each(function(i, obj) {
                    ids[i] = $(obj).val();
                });
                var idStr = ids.join("-");
                alert(idStr);

                $('#actpic').uploadify("settings","formData",{'idStr':idStr,'other_tagsname':other_tagsname,'remark_name':remark_name,'statistical_form_name3':statistical_form_name3});
            },
            <#--全部文件上传完触发(将信息进行发送)-->
             'onQueueComplete' : function(queueData) {
             alert("success");

             }
        });
    });
</script>

jsp中body:

<form id="addFile" class="pageForm required-validate" method="POST"  enctype="multipart/form-data" target="hidden_frame">

            <div style="height:160px;">

                <input type = "hidden" id = "getyearid" name = "getyearid" value = "${getyearid?default(0)}">

                <p>

                    <label>报表名称:</label>

                    <input name = "statistical_form_name3" id="statistical_form_name3" type="text" size="30" value = "${(statistical_form_name[0][2])?default("")}"/>

                </p>

                    <br/><br/><br/><br/>

                <p>

                    <label>备注:</label>

                    <input name = "remark_name" id="remark_name"  type="text" size="30" value = "${(statistical_form_name[0][5])?default("")}"/>     

                </p>

                    <br/><br/><br/><br/>

                <p>

                    <label>标签:</label>     

                    <#if tags?exists && statisform_obj_tags?exists>

                        <#list tags as tag>  

                            <#if tag[0]=="yes">

                                <${(tag[1])?default("")}>:${(tag[2])?default("")}

                                <input type="checkbox" name="tagsname" id="${(tag[2])}" value="${(tag[2])}"} checked>

                            <#else>

                                <${(tag[1])?default("")}>:${(tag[2])?default("")}        

                                <input type="checkbox" name="tagsname" id="${(tag[2])}" value="${(tag[2])}"} >

                            </#if>

                        </#list>

                    </#if>

                    <br/>

                    <#if tags?exists && !statisform_obj_tags?exists>

                        <#list tags as tag>

                             <${(tag[1])?default("")}>:${(tag[2])?default("")}

                             <input type="checkbox" name="tagsname" id="${(tag[2])}" value="${(tag[2])}"}>

                        </#list>

                    </#if>

                </p>

                <br/><br/><br/><br/><br/><br/><br/><br/><br/><br/> 

                <p>      

                    <label>其他标签:</label>

                    <label>(以逗号隔开)</label>

                    <label>(例:**,**)</label>

                    <input name = "other_tagsname" id="other_tagsname" type="text" size="30" value = "${(other_tagsname)?default("")}"/> 

                </p>     

                <br/><br/><br/><br/><br/><br/>

                <label style="width:60px;">选择文件:</label>

                <fieldset style="width:300px;border:1px solid #99BBE8;text-align:left;COLOR:#000000;FONT-SIZE:12px;font-family: Verdana;padding:5px;">               

                    <input name="actpic" type="file" id="actpic"/>

                </fieldset>

                <br/><br/><br/><br/>       

            </div>

            <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>

        </form>

 后台 action类中,

     

'formData':{'getyearid':${getyearid},'statisform_obj_id':${getyearid?default(0)},'statistical_form_name3':'1','remark_name':'1','other_tagsname':'1','idStr':'1'},

 这里面涉及到的数据 get set 下就可以得到。

下面解释下机制:

  因为我们用

     var statistical_form_name3 = $("#statistical_form_name3").val();

不能在这中间写

(function () {

('#actpic').uploadify({

所以选择写在onUploadStart方法函数里面,然后setting下,就成功把数据换上去。
这样后台轻松的获得。

至于这代码    ,版主我也觉得有点累。有些不必看的不用看。

谢谢阅读,共同进步,一起分享,美好明天。

时间: 2024-09-20 00:04:15

struts2整合uploadify插件怎样传参数的相关文章

firefox浏览器用jquery.uploadify插件上传时报HTTP 302错误

 这篇文章主要介绍了firefox浏览器用jquery.uploadify插件上传时报HTTP 302错误,分析了下,原来是利用flash进行post上传时没有包含原来的session信息,而是重新创建了一个session,知道原因了,我们来看看如何解决吧.     解决了uploadify插件在chrom频繁崩溃的问题,又遇到了新问题,ff浏览器下报HTTP 302错误, ff浏览器下 uploadify 利用flash进行post上传时没有包含原来的session信息,而是重新创建了一个se

用uploadify插件上传文件,本地能上传成功,但是上传到服务器就报错

问题描述 用uploadify插件上传文件,本地能上传成功,但是上传到服务器就报错 上图是根据网上找的例子修改了的,结果本地上传都失败, 上图是之前的,在本地发布都能上传成功,但是到服务器发布都不行了 大家知道是什么问题么,琢磨好长时间了都没弄出来 解决方案 服务器对应的上传目录没有相应的读写权限,上传到服务器需要Server.mappath将目录的虚拟路径转换为物理路径,这样才能上传成功 解决方案二: 基于jquery的上传插件Uploadifyuploadify上传文件插件的的使用 解决方案

firefox浏览器用jquery.uploadify插件上传时报HTTP 302错误_jquery

解决了uploadify插件在chrom频繁崩溃的问题,又遇到了新问题,ff浏览器下报HTTP 302错误, ff浏览器下 uploadify 利用flash进行post上传时没有包含原来的session信息,而是重新创建了一个session,新的session无法通过登录验证,因此被重定向到了登录页面. 解决的方法无非就是将原session一起post到服务器端,然后服务器端登录验证之前将需要验证的session改为post过来的那个...(语言组织能力太差-,-). jquery.uploa

ThinkPHP整合Uploadify插件实现异步上传图片

1.首先到官网下载Uploadify插件. 2.在页面引入uploadify.css.jquery.uploadify.min.js.当然你得先把jquery引入. 3.配置uploadify:  代码如下 复制代码 <script type="text/javascript">     $(function () {         var sid = '{:session_id()}';         $('#file_upload').uploadify({    

Struts2结合uploadify文件上传,后台抛出异常还是显示上传成功了。。。

问题描述 遇到了几个问题..没什么思路去解决,求大神相助......前台用的easyui和uploadify,后台用Struts2.3action1,struts2用action处理文件上传,配置了的input的Result,但是发现就算出错了也不会跳转....2,后台出错了,前台的uploadify还是显示上传成功了,但是文件并没有真正的上传成功uploadify有个事件onUploadError(file,errorCode,errorMsg,errorString)文件上传出错时触发,参数

easyui-用Uploadify插件上传文件,结果调试执行正常,普通运行无反应

问题描述 用Uploadify插件上传文件,结果调试执行正常,普通运行无反应 很蛋疼的一个问题,调试正常,普通运行无反应,firebug上面显示 404错误, "重新载入页面以获取源代码: http://localhost:3580/DOC/Uploadify/uploadify.swf?preventswfcaching=1439371047848" 这到底是什么原因导致的, 顺便问一下,用js怎样获取要上传的文件名和路径 解决方案 最可能的是路径问题,用fiddler抓包调试下.

jQuery.Uploadify插件实现带进度条的批量上传功能_jquery

本文实例讲述了jQuery.Uploadify插件实现带进度条的批量上传功能.分享给大家供大家参考,具体如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpLoad.aspx.cs" Inherits="UploadifyDemo_UpLoad" %> <html xmlns="http://www.w3.org/1999/xh

uploadify多文件上传参数设置技巧_jquery

比起swfupload,uploadify插件配置使用都更简单,只是刚加载的时候稍微慢了一秒左右. 废话不多说了,直接给大家贴代码了. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8″ /> <title>php jquery

详解jQuery uploadify文件上传插件的使用方法_jquery

uploadify这个插件是基于js里面的jquery库写的.结合了ajax和flash,实现了这个多线程上传的功能. 现在最新版为3.2.1. 在线实例 实例中用到的php文件UploaderDemo.php请在页面下方下载 引入文件 <link rel="stylesheet" type="text/css" href="uploadify.css" /> <script type="text/javascript