[英]Error while using Uploadify
I am new to Jquery, I have a problem regarding uploading the files using Uploadify. 我是Jquery新手,在使用Uploadify上传文件时遇到问题。 Iam trying to send a file to the Java Servlet which uploads the file using apache commons. 我试图将文件发送到Java Servlet,该Java Servlet使用apache commons上传文件。 But while executing the code, it is not all going to servlet. 但是,在执行代码时,并不会全部使用servlet。 I actually took this sample example from web and trying it. 实际上,我从网络上获取了此示例示例并进行了尝试。 Can anyone advice what am i missing? 谁能告诉我我想念什么? I am pasting the client code below: 我在下面粘贴客户端代码:
My understand is "script" parameter in uploadify function will call the servlet. 我的理解是uploadify函数中的“脚本”参数将调用servlet。 so, I have written my Servlet name in script parameter. 因此,我在脚本参数中写了我的Servlet名称。
Please advice me how to proceed further. 请告诉我如何继续进行。
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SimpleFileUpload</title>
<script type="text/javascript" src="js/swfobject.js"></script>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.v2.1.0.min.js"></script>
<link rel="stylesheet" href="css/uploadify.css" type="text/css" media="screen"/>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'uploader' : 'swf/uploadify.swf',
'script' : 'fileupload',
'cancelImg' : 'img/cancel.png',
'multi' : false
});
});
</script>
</head>
<body>
<h1>Simple File Upload</h1>
<h3>Multiple file upload made easy</h3>
<div id="file_upload"></div>
<br/>
<input type="button" value="Clear Queue" onclick="$('#file_upload').uploadifyClearQueue();"/>
<input type="button" value="Submit Queue" onclick="$('#file_upload').uploadifyUpload();"/>
</body>
and my servlet code is 而我的servlet代码是
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (ServletFileUpload.isMultipartContent(request)){
// Parse the HTTP request...
try {
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
Iterator itr = fileItemsList.iterator();
while(itr.hasNext()) {
FileItem item = (FileItem) itr.next();
// check if the current item is a form field or an uploaded file
if(item.isFormField()) {
// get the name of the field
String fieldName = item.getFieldName();
// if it is name, we can set it in request to thank the user
if(fieldName.equals("name"))
request.setAttribute("msg", "Thank You: " + item.getString());
} else {
File fullFile = new File(item.getName());
String filename = item.getName();
File targetdir = new File("E:/");
File savedFile = new File(targetdir,fullFile.getName());
item.write(savedFile);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
} //end servletFileUpload
Thanks, 谢谢,
我只是使用swfupload ...使用小提琴手,我看到我的基本示例只是使用uploadify提交了1个文件,所以我放弃了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.