English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How Do I upload a file to server using java servlets/JSP

2006-11-13 23:31:41 · 1 answers · asked by raghava 2 in Computers & Internet Programming & Design

1 answers

Create a page with an HTML form similar to the following. The input tag with a type of "file" shows up in the browser as a text field for the file name and a "browse" button automatically:








Now, in the JSP file or servlet that is receiving the post (upload.jsp in this case), processing a multipart form in Java without a pre-existing libray is a nightmare. I've done it, and trust me when I say this: don't. You have to literally get the form as a big MIME-encoded String, find the MIME part with the uploaded file, and then extract & decode the file. Don't do this unless you have a lot of time on your hands. The Jakarta Commons project has a nifty FileUpload class (see linked "source") that will do all the dirty work for you And since it's from Jakarta Commons, it's an industry standard component you can feel confident using in a production environment.

2006-11-13 23:53:41 · answer #1 · answered by watsonc64 3 · 2 0

fedest.com, questions and answers