取的话可以这样(文件名,文件简述等)String aa = myUpload.getRequest().getParameter("aa")

解决方案 »

  1.   

    package com.harvest.dl.dangan.util;import javax.servlet.http.*;
    import javax.servlet.*;
    import javax.naming.*;
    import java.util.*;
    import java.io.*;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2002</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */public class ParsePutFileHttpStream {  private static final char CR = 13;
      private static final char LF = 10;  protected String boundary = null;
      protected Hashtable params = new Hashtable();
      private byte[] fileByte;  public ParsePutFileHttpStream(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        ServletInputStream in = request.getInputStream();
        BufferedInputStream bin = new BufferedInputStream(in);
        boundary = getBoundary(request.getHeader("content-type"));    PrintWriter out=response.getWriter();
        out.println("<html><body><pre>");
        out.println("boundary=\n"+boundary);
        out.println();    byte[] bytes = new byte[128];
        in.readLine(bytes, 0, bytes.length);
        String line = new String(bytes);
        Hashtable header = null;
        while (in.readLine(bytes, 0, bytes.length)>=0) {
            line = new String(bytes);
            if (line.startsWith("Content-Disposition:")) {
                out.println(line);
                System.out.println(line);
                header = parseHeader(line);
                updateParams(header);
            } else if (line.startsWith("Content-Type:")) {
                params.put("Content-Type",
                        line.substring("Content-Type:".length()).trim());
            } else {
                if (header!=null && bytes[0]==13) {
                    if (header.containsKey("filename")) {
                        displayParams(out);
                        out.println("  ...saving payload");
                      System.out.println("  ...saving payload");
                        paserFileStream(bin);
                        header = null;
                    } else {
                        String name = (String)header.get("name");
                        String value = getParameter(in).trim();
                        params.put(name,value);
                    }
                }
                if (line.indexOf(boundary)>=0) out.println(line);
                  if (line.indexOf(boundary)>=0) System.out.println(line);
            }
            bytes = new byte[128];
        }
        out.println(this.fileByte.length);
      }  private void paserFileStream(BufferedInputStream is) throws IOException{
        int c;
        PushbackInputStream input = new PushbackInputStream(is, 128);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        while ((c=read(input,boundary))>=0) out.write(c);
        fileByte=out.toByteArray();
        out.close();
        input.close();
      }  private String getParameter(ServletInputStream in)
              throws java.io.IOException {
          byte[] bytes = new byte[128];
          in.readLine(bytes, 0, bytes.length);
          return new String(bytes);
      }
      private String getBoundary(String contentType) {
          int bStart = contentType.indexOf("boundary=")+"boundary=".length();
          return "" + CR + LF + "--" + contentType.substring(bStart);
      }  private int read(PushbackInputStream input, String boundary)
              throws IOException {
          StringBuffer buffer = new StringBuffer();
          int index = -1;
          int c;      do {
              c = input.read();
              buffer.append((char)c);
              index++;
          } while ((buffer.length() < boundary.length()) &&
                  (c == boundary.charAt(index)));
          if (c == boundary.charAt(index)) {
              int type = -1;
              if (input.read() == '-')
                  type = -2;
              while (input.read() != LF);
              return type;
          }
          while (index >= 0){
              input.unread(buffer.charAt(index));
              index--;
          }
          return input.read();
      }  private Hashtable parseHeader(String line) {
          Hashtable header = new Hashtable();
          String token = null;
          StringTokenizer st = new StringTokenizer(line, ";");
          while (st.hasMoreTokens()) {
              token = st.nextToken().trim();
              String key = "";
              String val = "";
              int eq = token.indexOf("=");
              if (eq < 0) eq = token.indexOf(":");
              if (eq > 0) {
                  key = token.substring(0, eq).trim();
                  val = token.substring(eq+1);
                  val = val.replace('"',' ');
                  val = val.trim();
                  header.put(key, val);
              }
          }
          return header;
      }  private void updateParams(Hashtable header) {
          for(Enumeration e = header.keys(); e.hasMoreElements();) {
              String key = (String)e.nextElement();
              params.put(key, header.get(key));
          }
      }  private void displayParams(PrintWriter out) {
          for(Enumeration e = params.keys(); e.hasMoreElements();) {
              String key = (String)e.nextElement();
              System.out.println("  "+key+" = "+params.get(key));
          }
      }  public byte[] getFileByte() {return this.fileByte;}  public Object getParams(String param) {
        return params.get(param);
      }  protected void finalize() {
        params.clear();
        params=null;
      }}