在一个JSP页面里有两个FORM,一个是看得见的,一个是隐藏的,内容都一样,就一个上传文件框,用户只需填一个FORM,另一个隐藏的要自动获得第一个FORM里的内容,并提交到不同的ACTION里.该如何做呢?谢谢指教...我是用JS这样弄的,但不行...
<script language=javascript>
<!--
function OnButton1()
{
    document.Form1.action = "http://www.aaa.com/test/a.do" 
    document.Form1.submit(); 
    var upfile=document.Form1.theFile;
    document.Form2.theFile=var upfile;
    document.Form2.action = "http://www.bbb.com/test/b.do"
    document.Form2.submit(); 
    return true;
}
-->
</script>

解决方案 »

  1.   

    很有意思的问题啊,哈哈  var upfile=document.Form1.theFile;
    ---------->
      var upfile=document.Form1.theFile.value; 
    document.Form2.theFile=var upfile;
    ------->
     document.Form2.theFile=upfile;可以的,你再试试,或者把其中一个form的target设置为_blank,看得比较清楚
    或者用httpwatch跟踪下
      

  2.   

    为两个form设置不同的target<form name="form1" target="fm1"></form><form name="form2">
    </form><iframe style="display:none" name="fm1"></iframe><script language=javascript>
    <!--
    function OnButton1()
    {
    document.Form1.action = "http://www.aaa.com/test/a.do"
    document.Form1.submit();
    var upfile=document.Form1.theFile;
    document.Form2.theFile=var upfile;
    document.Form2.action = "http://www.bbb.com/test/b.do"
    document.Form2.submit();
    return true;
    }
    -->
    </script>
      

  3.   

    LS两位大哥,程序只把Form1给submit了,Form2就没做
      

  4.   

    你把其中一个form的target设置为_blank就可以看到都提交了你的js有错,我上面给出了修改。。你也可以用httpwatch跟踪下,肯定都提交了
      

  5.   

    不好意思还有错
    function OnButton1()
    {
        var upfile=document.Form1.theFile;
        document.Form2.theFile=var upfile; // document.Form2.theFile=upfile;
        document.Form1.action = "http://www.aaa.com/test/a.do";//少逗号
        document.Form2.action = "http://www.bbb.com/test/b.do";//少逗号
        document.Form1.submit(); 
        document.Form2.submit(); 
        //return true;
    }//顺序是否有关,自己测试下
      

  6.   

    改了,确实都提交了,但form2里是空的......
      

  7.   

    md,我也糊涂了    var upfile=document.Form1.theFile;
        document.Form2.theFile=var upfile; // document.Form2.theFile=upfile;
    ----〉
     var upfile = document.Form1.theFile.value;
      document.Form2.theFile.value=upfile
      

  8.   

    aimer311...我郁闷啊,Form2虽然提交了,但总是空的...
      

  9.   

    <script language=javascript>
    <!--
    function OnButton1()
    {
        document.Form1.action = "http://www.aaa.com/test/a.do";    
        var upfile=document.Form1.theFile.value;    alert (upfile);    document.Form2.theFile.value=upfile;    alert (document.Form2.theFile.value);    document.Form2.action = "http://www.bbb.com/test/b.do";
        document.Form1.submit(); 
        document.Form2.submit(); 
        return true;
    }
    -->
    </script>第一个alert有值,第二个是空的...
      

  10.   

    提交form前设置form1的target属性,不能让form1提交的目标为_self,如果两个form内容一样的话可以让form提交2次,每次提交前设定action
      

  11.   

    我说会不会是form里的enctype="multipart/form-data"有问题啊
      

  12.   

    有一点不明白为什么要用二个FORM 为做不同的ATION 完全可以 一个做好马上做后一个
    只要struts-config.xml配一下不就可以了
      

  13.   

    因为如果form里有enctype="multipart/form-data"是不能提交到两个action里的,所以只能做两个一样的
      

  14.   

    http://cache.baidu.com/c?word=input%2Cfile%2C%B8%B3%D6%B5&url=http%3A//topic%2Ecsdn%2Enet/t/20031119/09/2470653%2Ehtml&p=882a964794890abc0aa6c7710d1597&user=baiduhttp://cache.baidu.com/c?word=input%2Cfile%2C%B8%B3%D6%B5&url=http%3A//www%2Echinesedev%2Ecom/archiver/tid%2D47057%2Ehtml&p=92769a45d6db52ff57ea9668534b9d&user=baidu我也学习了,谢谢
      

  15.   

    不设两个表单,在javascript中提交同一个表单,每次的action的值不同,target也可不同,根据需要,当执行完action的那两个页面,选一个关了它.留一人显示.
    不知道这样行不行?
    新手,多多指教。
      

  16.   

    jsp7274的方法可行,谢谢了
    PS,咋给分哪,小弟第一天来,不懂规矩
      

  17.   

    其实你你只要把第一FORM的内容方到SESSION中去
    第二个ATION时你只要去拿就可以了不用做的那么高难度
      

  18.   

    aimer311说得好:有问题,先百度、再google、再csdn相关问题、最后提问.
    大家交流交流.分的事只是一个游戏规则.
    另:在问题列表处的最右边,有一个"管理" 点,在里面输入密码,然后给分,确定.
      

  19.   

    回njp20033266njp,两个action部署在不同的服务器上,放在session里拿不到...
    另:分已给,不知道拿到没?
      

  20.   

    "在一个JSP页面里有两个FORM,一个是看得见的,一个是隐藏的,内容都一样,就一个上传文件框,用户只需填一个FORM,另一个隐藏的要自动获得第一个FORM里的内容,并提交到不同的ACTION里.该如何做呢?谢谢指教..."这种操作是不会成功的!
    因为上传文件框实际上是一个控件,它必须是通过鼠标点击选择文件然后获得值,而不能直接通过Javascript给它赋值!
    所以你的Form2怎么都不能上传成功的!