0
的index.jsp無法通過額外的價值,而使用uploadify V3.2.1
<h1>Uploadify Demo</h1>
<form id="uploadForm">
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
<input type="text" id="fileName" name="fileName"/>
</form>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'swf' : 'uploadify.swf',
'uploader' : '../upload',
'formData': { 'fileName': $('input:text[name:fileName]').val() }
});
});
</script>
upload.java上傳文件
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
final String UPLOAD_DIRECTORY = request.getSession().getServletContext().getRealPath("/upload");
//process only if its multipart content
if (ServletFileUpload.isMultipartContent(request)) {
try {
List<FileItem> multiparts = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
String name = new File(item.getName()).getName();
item.write(new File(UPLOAD_DIRECTORY + File.separator + name));
}else{
System.out.print("Here 1 "+request.getParameter("fileName"));
}
}
//File uploaded successfully
request.setAttribute("message", "File Uploaded Successfully");
} catch (Exception ex) {
request.setAttribute("message", "File Upload Failed due to " + ex);
}
} else {
request.setAttribute("message",
"Sorry this Servlet only handles file upload request");
}
// request.getRequestDispatcher("/result.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
}
}
我一直都想與Here 1 null
,這意味着null
值爲fileName
。任何人都可以幫助我,弄清楚,我應該怎麼做才能正確地獲得價值。