servlets - HTML File upload form with additional input fields -


i have following html form...

<html> <head><title>upload servlet</title></head> <body><h2>upload servlet</h2>  <form name='uploadparams' enctype='multipart/form-data' action='' method='post'>     <label>migrate options from:         <select name='migratefrom'>             <option></option>             <option value='version 1'>version 1</option>         </select>     </label>     <br/>     <input type='file' name='zipfile'>     <br/>     <input type='hidden' value='willnotshowupinservlet'/>     <button type='submit'>submit</button> </form> </body> </html> 

the problem while can read file http parameter name of "zipfile" fine servlet not see other parameters "willnotshowupinservlet" , "migratefrom". file upload forms able have 1 input (the file input)?

they indeed not available regular request parameters because you've set form encoding multipart/form-data (which indeed mandatory in order able include file content in request body). have parse request body conform multipart/form-data specification. getparameter() calls of servlet api supports form encoding of application/x-www-form-urlencoded default enctype of html <form> element.

a commonly used api ease job apache commons fileupload. or, when you're on servlet 3.0, need annotate servlet @multipartconfig. can find concrete examples of both approaches in this answer.


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -