multipart/form-data编码中有对应上传文件的项:
boundary
Content-Disposition: form-data; name="file"; filename="yourfilename"
Content-Type.....

解决方案 »

  1.   

    楼上可否给出相关资料,比如相关书籍,RFC之类的^_^
      

  2.   

    <input type="file"  name="file_name" size="60" class="textbox"/>public void File(MultipartFormDataRequest mreq) throws Exception{
       Hashtable files=mreq.getFiles();
       if((files!=null)||(!files.isEmpty())){
          CosUploadFile file=(CosUploadFile)files.get("file_name");
    ........
       }}
      

  3.   

    楼上说的是JSP中的吗?先谢了:)只是在servlet中能否实现呢?
      

  4.   

    如果文件有几十m,也先写到数据库里?我想一定有直接从servlet中提取的办法的
      

  5.   

    在输入流中.有这样的
    Content-Disposition: form-data; name="file"; filename="FileName"Content-Type.....
    你在servlet中将输入流读出,获取filename后的字符,就可以得到
    "C:/path/FileName"或者"FileName"的字符串(操作系统不同),这样,最后一个“/”后面的就是文件名,
      

  6.   

    使用jspsmartupload,代码示例如下:
    <%@ page language="java" %>
    <%@ page contentType="text/html;charset=gb2312" %>
    <%
    response.setHeader("Cache-Control","no-cache"); //HTTP 1.1
    response.setHeader("Pragma","no-cache");  //HTTP 1.0
    response.setDateHeader ("Expires", 0);  //prevents caching at the proxy server
    %>
    <%@ include file="../DSS/s1dss.ini" %>
    <%@ page import = "com.jspsmart.upload.*,java.io.File,java.lang.String" %>
    <jsp:useBean id="fileUpload" scope="page" class="com.jspsmart.upload.SmartUpload"/><%
    String ptype = request.getParameter("ptype");
    String prow = request.getParameter("prow"); String filename = "";
    // Variables
    int count=0;         // Initialization
    fileUpload.initialize(pageContext); fileUpload.setTotalMaxFileSize(maxfile); try{
    fileUpload.upload();
    filename = fileUpload.getFiles().getFile(count).getFileName();

    String newpath = uploadpath + "/" + filename;
    String urlval = request.getRequestURL().toString();
    String path = request.getServletPath();
    String domainname = urlval.replaceAll(path, newpath);
    domainname = new String(domainname.trim().getBytes(), "GB2312");

    try { // Save the files with their original names in the virtual path "/upload"
    // if it doesn't exist try to save in the physical path "/upload"
    count = fileUpload.save(uploadpath);
    } catch (Exception e) { 
    out.println(e.toString());
    }
    out.println("<script language='javascript'>");
    out.println("window.opener.frmInput.url.value = '" + domainname + "';");
    out.println("alert('文件上载完毕!')");
    out.println("window.close();");
    out.println("</script>");
    }
    catch(SecurityException se){
    out.println("<script language='javascript'>");
    out.println("document.location.href = 'reselect.jsp?ptype=" + ptype + "&prow=" + prow + "';");
    out.println("</script>");
    }
    %>
      

  7.   

    可以通过HttpServletRequest 的getInputStream() 方法得到一个输入流
    在文件中一定会有,Content-Disposition: form-data; name="file"; filename="FileName"这样的字符串(可通过getContentType() 得到),取FileName 就可以了,