由于特殊原因。需要再一个jsp页面页面里写两个form
每个form都action到不同的servlet进行处理,
问;大伙说说当我点击form a的"提交" 时,form b的bb内容会到达bservlet吗?
<body>
<form name="a" action="aservlet" method="post">
<input type="text" name="aa" >
<input type="submit" name="sub" value="提交">
</form>
<from name="b" action="bservlet" method="post">
<input type="text" name="bb" >
</form>
</body>

解决方案 »

  1.   

    Ajax 可以提交任意多个表单!
      

  2.   

    你不会formb里面也加个提交按钮阿
      

  3.   

    如果不会,那么如何才能使之会?
    因为一点击“提交”页面就刷新了,如果在form b里面再加上一个"提交"按钮的话根本没有用啊
      

  4.   

    会不会自己试验下就好了……
    如果不会自己写个JS在A递交的时候也剪辑B的提交按钮
      

  5.   


    <js>
    function get(){
    document.getelementById("bb1").value=document.getelementById("bb").value
    document.a.submit;
    }
    </js>
    <body>
    <form name="a" action="aservlet" method="post">
    <input type="text" name="aa" >
    <input type="text" name="bb" style="display:none" id="bb1">
    <input type="button" name="sub" value="提交" onclick="get();">
    </form>
    <from name="b" action="bservlet" method="post">
    <input type="text" name="bb" id="bb">
    </form>
    </body>
    也可以将BB的值加到URL后传过去,不过处理中文起来就麻烦点了……
      

  6.   

    这是我的测试代码,结果只能得到aa的值,bb却是不行,错在哪??
    <%@ page contentType="text/html;charset=GBK" language="java"%>
    <html>
    <head>
    <script type="text/javascript">
    function sub()
    var v=document.getElementById("b");
    v.submit();
    </script>
    </head>
    <body>
    <form name="a" id="a" action="#" method="post">
    <input type="text" name="aa" value="aa">
    <input type="submit" name="suba" value="提交" onClick="sub">
    </form>
    <form name="b" id="b" action="#" method="post">
    <input type="text" name="bb" value="bb">
    </form>
    <%  String aa=request.getParameter("aa");
        String bb=request.getParameter("bb");
    out.println("aa="+aa+"         "+"bb="+bb);
    %>
    </body>
    </html>
      

  7.   

    到达bservlet!!!寒,看错鸟,上面代码作废~~~
                             特此申明
      

  8.   

    大哥,我要写的真正应用是一张jsp包含两个form每个form提交数据到不同的servlet处理,
    我上面写的jsp只是测试页面,所以提交到当前页面处理,看看效果怎么样啊,
      

  9.   


    我说的是我自己的代码作废,你太快了,插了一脚……2个form能同时提交么?2个请求你让服务器先响应哪个呢?直接这样处理不了吧,先处理a,再处理b~
      

  10.   

    wsm106 兄的方法也试过了,也不行啊
    报错:对象不支持此属性或方法
      

  11.   

    呵呵,楼上的,真的不能同时提交两个form?
      

  12.   


    <body>
    <form name="a" action="aservlet" method="post">
    <input type="text" name="aa" >
    <input type="submit" id="aa" style:"display:none">
    </form>
    <from name="b" action="bservlet" method="post">
    <input type="text" id="bb" >
    <input type="submit" name="bb" style:"display:none">
    </form>
    <input type="button" value="tijiao" onclick="submitaandb();"
    </body>
    <js>
    function submitaandb(){
      document.getElementById("aa").click();
      document.getElementById("bb").click();
    }
    </js>
    不知道这样行不行?
      

  13.   

    参考下 我些的两个 form 分别提交上传图片的代码
    <%@ page import="javax.naming.*" contentType="text/html;charset=utf-8"%>
    <% 
    DQ.UserDO userDO = (DQ.UserDO)session.getAttribute("loginUser");
    DQ.FunctionDO[] functionDO = userDO.getFunction();
    boolean isChked = false;
    for(int i=0;i<functionDO.length;i++){
    if( functionDO[i].getId()==10)
    isChked = true;
    }

    if(!isChked) return ;
    Object obj = session.getAttribute("UploadLogo");
    if(obj !=null){
    Exception e = (Exception) obj;
    String errMsg = e.getMessage();
    out.print("<script language='javascript'>alert('"+errMsg+"')</script>");
    } session.setAttribute("UploadLogo", null);
    %>
    <style type="text/css">
    <!--
    .STYLE1 {
    font-size: 12px;
    font-style: italic;
    }
    -->
    </style><DIV align="center">
      <form action="UploadLogo?logoType=big" id='thisform' name='thisform' method='post' enctype="multipart/form-data">
    <table cellpadding="0" cellspacing="0" cols="1" width="100%">
    <tr>
    <td colspan="1" valign="bottom" align="left" height="20"><strong>Upload logo in the login page </strong></td>
    </tr>
    <tr >
    <td colspan="1">
    <hr width="100%">
    </td>
    </tr>
    <tr>
    <td>
    <table cellpadding="7" cellspacing="7" cols="2" width="100%">
    <tr >
    <td bgcolor="#eeeeee" width="100" colspan="1" align="right"><br /> </td>
      <td bgcolor="#eeeeee" colspan="1" ><br />
          <input type="file" id="filePath" name="filePath" size="70">
    <br />
    <span class="STYLE1">(File format: jpg. Suggested image size: 275x93 pixels.)
    </span></td>
    </tr>
    <tr bgcolor="#eeeeee">
    <td colspan="2" align="center">
    <input style="CURSOR: hand" type="submit" id="upload" name="upload" value="Upload" >

    <input style="CURSOR: hand" type="reset" id="clear" name="clear" value="Reset" > </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </DIV>
    <p>&nbsp;</p>
    <form action="UploadLogo?logoType=small" id='thisform2' name='thisform2' method='post' enctype="multipart/form-data" >
      <table cellpadding="0" cellspacing="0" cols="1" width="100%">
        <tr>
          <td colspan="1" valign="bottom" align="left" height="20"><strong>Upload logo in the  page header </strong></td>
        </tr>
        <tr >
          <td colspan="1"><hr width="100%" />
          </td>
        </tr>
        <tr>
          <td><table cellpadding="7" cellspacing="7" cols="2" width="100%">
            <tr >
              <td bgcolor="#eeeeee" width="100" colspan="1" align="right"><br />
              </td>
              <td bgcolor="#eeeeee" colspan="1" ><br />
                    <input type="file" id="filePath" name="filePath" size="70" />
                    <br />
                    <span class="STYLE1">(File format: gif. Suggested image size: 113x25 pixels.)
              
                  </span></td>
            </tr>
            <tr bgcolor="#eeeeee">
              <td colspan="2" align="center"><input style="CURSOR: hand" type="submit" id="upload" name="upload" value="Upload"" />
                    <input style="CURSOR: hand" type="reset" id="clear2" name="clear2" value="Reset">
              </td>
            </tr>
          </table></td>
        </tr>
      </table>
    </form>
    <p>&nbsp;</p>
      

  14.   

    楼上的,也不行啊
    最后面的那个input到底属于哪个form?点击他页面无任何反映啊
      

  15.   

    BlackSky插的也太快了
    我说的楼上是你的楼上啊
      

  16.   


    <script type="text/javascript">
    function submit(){
    document.a.submit;
    document.a.submit;
    }
    </script >
    <body>
    <form name="a" action="aservlet" method="post">
    <input type="text" name="aa" >
    <input type="button" name="sub" value="提交" onclick="submit();">
    </form>
    <from name="b" action="bservlet" method="post">
    <input type="text" name="bb" id="bb">
    </form>
    </body>这样可以同时提交多个表单,并且后台servlet的处理顺序和表达的提交顺序是一样的,如果在servlet里有页面跳转的话,那么执行完后跳转的页面取决于最后执行的servlet
      

  17.   

    document.a.submit;
    document.a.submit;-----------------
    写错了,
    document.a.submit;
    document.b.submit;你在2个servlet里打印点东西看看,看程序是否运行到那里了
      

  18.   

    我那个写错了 
    document.getElementByName("bb");
    应该是getElementById
      

  19.   


    根据你的解法。我改了测试页面。代码如下.
    因为一张jsp就是一个 servlet。现在,测试页面的action暂时提交到本页,说明这两个form是提交到同一个servlet.如果提交到两个不一样的servlet处理,那么提交到同一个servlet应该也没有问题吧?,可是,我就是测不通啊
    <%@ page contentType="text/html;charset=GBK" language="java"%>
    <html>
    <head>
    <script type="text/javascript">
    function submit(){
    document.a.submit;
    document.b.submit;
    }
    </script>
    </head>
    <body>
    <form name="a" action="#" method="post">
    <input type="text" name="aa" >
    <input type="button" name="sub" value="提交" onclick="submit();"></form>
    <form name="b" action="#" method="post">
    <input type="text" name="bb" id="bb">
    </form>
    </body>
    <%  String aa=request.getParameter("aa");
        String bb=request.getParameter("bb");
    out.println("aa="+aa+"         "+"bb="+bb);
    %>
    </html>
      

  20.   

    我写了2个servlet测试过,是可以的,不知道你哪里出问题了,慢慢研究吧……
      

  21.   

    我想问LZ  为什么要用到两个form如果是自己的一些想法的话,完全可以自己做试验看看。
      

  22.   

    一言难尽,确实是被逼着用两个form
      

  23.   

    同一个页面只能用一个servlet来处理。
      

  24.   

    不会,用JAVASCRIPT控制跳转路径,然后丢进去时,指定丢进去的FORM
      

  25.   

    在form里面传一个HIDDEN么  来控制哪个提交的 传到本身 判断是那个提交按扭  再转向
      

  26.   

    用javascript 写两个方法,document.forms[0] document.forms[1].用两个不同的按钮,一个按钮调用一个方法.可以不?
      

  27.   

    <script type="text/javascript">
       function checka() {
       var f  = document.forms[0];
       f.submit();
       }
      
    function checkb() {
    var f  = document.forms[1];
    f.submit();
       }
      
      </script>
      
      <body>
    <form name="a" action="aservlet" method="post">
    <input type="text" name="aa">
    <input type="button" name="sub" value="提交a" onclick="checka()">
    </form>
    <form name="b" action="bservlet" method="post">
    <input type="text" name="bb">
    <input type="button" name="sub" value="提交b" onclick="checkb()">

    </form> </body>
    我只写了这个页面测试,这样是可以的.楼主再试试.
      

  28.   

    应该是不行的 提交在相应的form里 应该执行相应的action