<div id="apDiv12">
<form id="form4" class="well" name="form4" method="post" action="product" enctype="multipart/form-data">
<select name="catogory" id="catogory" >
<option value="Select your catogory" selected="1">Select your catogory</option>
<option value="Classical">Classical</option>
<option value="Rock">Rock</option>
<option value="R&B">R&B </option>
<option value="Hio Hop">Hio Hop</option>
<option value="Jazz">Jazz</option>
<option value="Country">Country</option>
<option value="Rap">Rap</option>
<option value="Reggae">Reggae</option>>
</select>
<div id="apDiv17">
<div id="apDiv18">Upload lyrics file..</div>
<div id="apDiv19">Upload voice track..</div>
<div id="apDiv20">Submit..</div>
<div id="apDiv21"><input class="span3" name="lyrics" type="file" /></div>
<div id="apDiv22"><input class="span3" name="voice" type="file" /></div>
<div id="apDiv23"><input class="btn btn-primary" type="submit" name="upload" id="upload" value="Submit" /></div>
</div>
</form>
但是这个代码我得到null值.... 在这种情况下,值传递在doGet方法中工作。但文件上传无效。
私人决赛字符串UPLOAD_DIRECTORY =“/ media / shanaka / New Volume / munity”;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
PrintWriter writer = resp.getWriter();
String catogary = req.getParameter("catogory");
writer.print(catogary);
//process only if its multipart content
if (ServletFileUpload.isMultipartContent(req)) {
try {
List<FileItem> multiparts = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(req);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
String name = new File(item.getName()).getName();
item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
}
}
//File uploaded successfully
req.setAttribute("message", "File Uploaded Successfully");
} catch (Exception ex) {
req.setAttribute("message", "File Upload Failed due to " + ex);
}
} else {
req.setAttribute("message",
"Sorry this Servlet only handles file upload request");
}
}
我已经尝试将@MultipartConfig
放在servlet中,但是Category Field为null。