比如form1.submit();form2.submit();
之所以问这个问题是因为我现在有个困惑,我在做一个文件上传的页面,
form如下
<form name="uploadForm" method="post" action="uploadfile.jsp" enctype="multipart/form-data">
但是这样其他input里面的值就传不到后台了,所以我想用两个form,一个
上传文件,一个传值,不知道可行不

解决方案 »

  1.   

    两个form 一个负责上传文件  另外一个是相关的信息 默认file为null不就成了
      

  2.   

    用一个form就可以实现你要的效果,一是用专用的上传组件,根据组建提供的接口就可以得到上一个页面的input值.如果不用组件就用javascript把参数和参数值加到url里传到uploadfile.jsp就可以了
      

  3.   

    一个页面可以使用多个FORM可以提交给不同的程序处理也可以提交给相同程序处理,只要你控制的没有问题,LZ的意思是想一次提交 2个FORM的内容吧? 写个script应该没问题。
      

  4.   

    vacuumboy(菜鸟依旧)
    说的对.
      

  5.   

    现在的问题是text,hidden和file有冲突,加上enctype="multipart/form-data" 只能传
    file的IO流,不加只能传text和hidden的值,我现在要它们都能一次传到后台。
    真是郁闷死了
      

  6.   

    将form中的name定义不同的名字
      

  7.   

    写个SCRIPT
    function subForms(){
    form1.submit();
    form2.submit();
    }
    这样不是两个一起提交?
      

  8.   

    一个表单就可以处理了,你可以找一个上传用的包,我现在用的是commons-fileupload-1.0.jar,不过据说很难找到了。用这种第三方的包来处理提交的内容就可以了。
      

  9.   

    一个页面里可以写2个form,但是楼主的问题没有必要写两个form,传一个标志位,判断是传文件还是传值就可以了。
      

  10.   

    楼主的问题我在前些日子也遇到过,不如要做一个文章配图(表单提交文章标题,内容等信息,文章配图是通过type='file'来上传一幅图片),分开来做十分简单,表单提交到servlet通过javabean实现添加,上传使用jspsmartupload.jar也十分方便,但是两者合一是否可以实现呢?我做的是通过一个jump.jsp来实现的,说白了就是先上传后提交
    在jump.jsp<%@ page contentType="text/html;charset=GBK" %>
    <%@ page language="java" import="com.jspsmart.upload.*"%>
    <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
      <BODY BGCOLOR="white">
        <%
        //初始化文件名和上传结果
        String FileName = "noImage";
        String result ="error";
        try
        {
          // 执行初始化操作
          mySmartUpload.initialize(pageContext);
          //限制文件上传格式
          mySmartUpload.setAllowedFilesList("jpg,gif,bmp,jpeg");
          // 上传文件到服务器
          mySmartUpload.upload();      //如果有文件上传
          if(mySmartUpload.getFiles().getCount()>0)
          {
            // 取出文件
            com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
            //
            //如果文件存在
            if(myFile.getSize()>0)
            {
              String k = myFile.getFileExt();
              java.util.Date d = new java.util.Date();
              FileName = d.getTime()+ k;
              myFile.saveAs("/upload/" +FileName);
              result="success";
            }
            else
            {
              System.out.println("文件不存在!");
              //result="error";
            }
          }
          else
          {
            System.out.println("没上传!");
            //result="error";
          }
        }
        catch(Exception ex)
        {
          System.out.println(ex);
          //result="error";
        }
        finally
        {
          //存储表单信息
          String Uid = mySmartUpload.getRequest().getParameter("Uid");
          String Atitle = mySmartUpload.getRequest().getParameter("Atitle");
          String Acontent = mySmartUpload.getRequest().getParameter("Acontent");
          request.setAttribute("Uid",Uid);
          request.setAttribute("Atitle",Atitle);
          request.setAttribute("Acontent",Acontent);
          request.setAttribute("FileName",FileName);
          request.setAttribute("Result",result);
        }
        %>
        <jsp:forward page="servlet1"/>
      </BODY>
    </HTML>
      

  11.   

    用apache的文件上传包commons-fileupload-1.0.jar
    下载地址:http://jakarta.apache.org/commons/fileupload/
    用一个FORM提交,其他的input都给上不同的名字。
    例如:<INPUT type="text" name="MASTER_REVDATE" maxlength="10" size="20">
    在服务端这么来取:
    String _revDate = ((ParamPart)paramMap.get("MASTER_REVDATE")).getValue();
    另外写一个方法来取得上传流的各部分
    protected HashMap getMultipartMap(HttpServletRequest request) throws EconException {
    final int MAX_CONTENT_LENGTH = 1024 * 1000 * 10;

    MultipartParser parser = null;
    HashMap paramMap = new HashMap();
    Part eachPart = null;

    try {
    parser = new MultipartParser(request, MAX_CONTENT_LENGTH);

    List params = parser.getEachParts();
    for(int i=0 ; i<params.size() ; i++) {
    eachPart = (Part)params.get(i);
    paramMap.put(eachPart.getName(), params.get(i));
    }

    return paramMap;
    } catch (FileUploadException e) {
    if(e instanceof SizeLimitExceededException) {
    throw new EconException(EconException.UPLOAD_SIZE_ERROR, e);
    } else {
    throw new EconException(EconException.ERROR, e);
    }
    } catch (Exception e) {
    throw new EconException(EconException.ERROR, e);
    }
    }
      

  12.   

    一次只能提交一个,
    楼主的问题关键在于对enctype="multipart/form-data"的form不会处理
    非file型input值吧,根据你使用的组件不同,这个有区别,
    给你个用apache的文件上传包commons-fileupload-1.0.jar的代码:
    (请注意//*******提示的部分的处理方式)package edu.lynu.webexam.servlet;import java.io.*;
    import java.util.*;
    import java.text.*;
    import javax.servlet.*; 
    import javax.servlet.http.*;
    import edu.lynu.webexam.common.CommonObjects;
    import org.apache.commons.fileupload.*;public class UploadServlet extends WebExamBaseServlet {     private static String ABSOLUTE_UPLOAD_PATH ;     //Process the HTTP Get request 
    public void doGet(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException { 
    HttpSession session = request.getSession(true);        
    }  public void doPost(HttpServletRequest request, HttpServletResponse response) 
    throws ServletException, IOException { 
            try{     
                ABSOLUTE_UPLOAD_PATH = CommonObjects.WEBAPP_ROOT+"uploads\\";
                File new_path = new File(ABSOLUTE_UPLOAD_PATH);
                if(false == new_path.exists())  new_path.mkdir();
                            
                DiskFileUpload fu = new DiskFileUpload();
                // maximum size before a FileUploadException will be thrown
                fu.setSizeMax(1000000);
                // maximum size that will be stored in memory
                fu.setSizeThreshold(4096);
                // the location for saving data that is larger than getSizeThreshold()
                fu.setRepositoryPath(ABSOLUTE_UPLOAD_PATH);
        
                List fileItems = fu.parseRequest(request);
                System.out.println("total variable numbers="+fileItems.size());
                
                Iterator i = fileItems.iterator();
                
                //******* assume it is variable 'process_id"  
                FileItem fi1=(FileItem)i.next();
                System.out.println("fi1.getFieldName()="+fi1.getFieldName());
                System.out.println("fi1.getString()="+ fi1.getString() ); //correct!
                
                //******* assume it is variable 'compart_symbol"
                FileItem fi2=(FileItem)i.next();
                System.out.println("fi2.getFieldName()="+fi2.getFieldName());
                String compart_symbol = fi2.getString();
                System.out.println("fi2.getString()="+ fi2.getString() ); //correct!
                
                //>>>>>>> assume it is variable 'import_txt" file control
                FileItem fi3 = (FileItem)i.next();
                System.out.println("fi3.getFieldName()="+fi3.getFieldName());
                String fileName_tmp = fi3.getName();
                System.out.println("fi3.getName()="+ fi3.getName() ); 
                String fileName_no_path = fileName_tmp.substring(fileName_tmp.lastIndexOf("\\")+1);
                File fileToWrite = null;
                if( fi3.getInputStream().available()>0 ){
                    fileToWrite = new File( ABSOLUTE_UPLOAD_PATH + fileName_no_path );
                    fi3.write(fileToWrite);                              
                }
                
                if( fileToWrite != null && true==ImportTxtFile(fileToWrite, compart_symbol) ){
                    request.setAttribute("file_name",(ABSOLUTE_UPLOAD_PATH + fileName_no_path).replace("\\","/"));
                    request.getRequestDispatcher(CommonObjects.JSP_ROOT2+"UploadOK.jsp").forward(request, response);
                }else{
                    response.sendRedirect(CommonObjects.JSP_ROOT+"error.jsp");
                }
                
            }catch(Exception e){
               System.out.println("Exception ocurred while UPLOAD"+e); 
               e.printStackTrace();
               response.getOutputStream().println("upload fail");
               return;
            }        
            
    }

    private boolean ImportTxtFile( File import_txt_file, String symbol ) {
        return true;
    }

    }
      

  13.   

    嘿嘿,我正在做的一个东西里面正好有一个表单提交到多个地方<FORM METHOD="POST" ACTION="index.asp" NAME="info" onSubmit="return document.returnValue;">
    <INPUT TYPE="text" NAME="ID" >
    <INPUT TYPE="submit" value="对 比" onclick="document.info.action='Compare.asp'; return document.returnValue;">
    <INPUT TYPE="submit" value="删 除" onclick="document.info.action='index.asp?Action=Del'; return document.returnValue;">
    <INPUT TYPE="submit" value="修 改" onclick="document.info.action='index.asp?Action=Edit'; return document.returnValue;">
    <INPUT TYPE="submit" value="刷 新" onclick="document.info.action='index.asp?Action=ReOrder'; return document.returnValue;">
    <INPUT TYPE="submit" value="广 告" onclick="document.info.action='index.asp?Action=Ad'; return document.returnValue;">
    <INPUT TYPE="submit" value="已 售" onclick="document.info.action='index.asp?Action=Sale'; return document.returnValue;">
    </form>
    这样就可以了
      

  14.   

    to cn8cn(蓝码) 
    我是多个form提交到一个地方,老大
      

  15.   

    document.forms[0].submit();
    document.forms[1].submit();
    document.forms[2].submit();
    .
    .
    .
    .
    document.forms[N].submit();
      

  16.   

    // 新建一个SmartUpload对象
        SmartUpload su = new SmartUpload();
        // 上传初始化
        su.initialize(pageContext);
    //不要用request.getParameter(name);//用SmartUpload 提供的方法等到request就可以了
    su.getRequest().getParameter( "Uid ");