how to read text parameter from multipart/form-data form?

Discussion in 'Java' started by buu, May 24, 2009.

  1. buu

    buu Guest

    So, I have a servlet app. using org.apache library..
    I put a form as:
    <form style="align: center" id="dddd" method="post"
    enctype="multipart/form-data" action="Controller">
    Upload image:&nbsp;<input type="file" title="" name="file"
    accept="image/gif, image/jpeg" />
    <br/><br/>
    or paste URL:&nbsp;<input type="text" title="" name="urll"
    maxlength="140" size="40" accept="" /><br/>
    <input type="submit" title="" value="Search"/>
    </form>

    now, I would like to read a value of urll parameter, but I don't know how..
    any example like

    FileItemStream item = (FileItemStream)iter.next();
    String name = item.getFieldName();
    InputStream stream = item.openStream();
    System.out.println("name: "+name);

    does not work..
    how could I do that?
    buu, May 24, 2009
    #1
    1. Advertising

  2. buu

    Arne Vajhøj Guest

    buu wrote:
    > So, I have a servlet app. using org.apache library..
    > I put a form as:
    > <form style="align: center" id="dddd" method="post"
    > enctype="multipart/form-data" action="Controller">
    > Upload image:&nbsp;<input type="file" title="" name="file"
    > accept="image/gif, image/jpeg" />
    > <br/><br/>
    > or paste URL:&nbsp;<input type="text" title="" name="urll"
    > maxlength="140" size="40" accept="" /><br/>
    > <input type="submit" title="" value="Search"/>
    > </form>
    >
    > now, I would like to read a value of urll parameter, but I don't know how..
    > any example like
    >
    > FileItemStream item = (FileItemStream)iter.next();
    > String name = item.getFieldName();
    > InputStream stream = item.openStream();
    > System.out.println("name: "+name);
    >
    > does not work..


    Here is a snippet:

    DiskFileUpload upload = new DiskFileUpload();
    List files = upload.parseRequest(request);
    for(int i = 0; i < files.size(); i++) {
    FileItem file = (FileItem)files.get(i);
    if(file.getFieldName().equals("description")) {
    String description = file.getString();
    out.println("description=" + description);
    }
    if(file.getFieldName().equals("file")) {
    String filename = "C:\\test.upl";
    file.write(new File(filename));
    }
    }

    Arne
    Arne Vajhøj, May 24, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    8
    Views:
    142,266
    zeeshanakhter2009
    May 26, 2012
  2. Duncan
    Replies:
    0
    Views:
    1,451
    Duncan
    Feb 24, 2006
  3. Kevin DeValck
    Replies:
    1
    Views:
    723
    7stud --
    May 17, 2011
  4. nate
    Replies:
    6
    Views:
    511
    MikeT
    Oct 11, 2004
  5. Replies:
    1
    Views:
    395
Loading...

Share This Page