Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Chooser

Status
Not open for further replies.

rza22gza

Programmer
Feb 20, 2002
9
0
0
US
I have a Web site that is using JSP. On 1 of the pages is a form that has a text box and a button. When the user clicks the button, I want a File Chooser dialog box to appear. Then after the user selects the needed file, the path and filename are put into the textbox. Can anyone help me accomplish this. Thanks. Jacob
 
Hello rza22gza,

What you are interested in is the input type of file (this is a standard HTML form object). For example:
Code:
    <input type=&quot;file&quot; name=&quot;fileInput&quot; size=&quot;50&quot;>
This will cause two things to appear on your page:

1. A text input field (where the path to the file goes)
2. A &quot;Browse...&quot; button, which when clicked on will bring up a file dialog box

Hope this helps,
Adam Rice
 
Thanks a million. I have another question, if you can help. Now that I know where the file is located locally. I want to copy it to the server. How is that accomplished. Thanks again.
 
When you use a file input field, the file is automatically sent as part of the request stream as multi-part MIME data.

You will generally need to use a MIME parsing utility on the server side to reconstitute the file from the request stream. I believe that there is a library that already does this available on servlets.com

Do a search on Google and you will turn up quite a few freely available utilities to do this for you. It isn't rocket science but why reinvent the wheel, eh?

Regards,

Charles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top