Java 使用Uploadify时出错
我是Jquery新手,在使用Uploadify上传文件方面遇到了问题。Iam试图向Java Servlet发送一个文件,该Servlet使用apache commons上传该文件。 但是,在执行代码时,并不是所有的代码都将由servlet完成。实际上,我从web上获取了这个示例并进行了尝试。谁能告诉我我错过了什么?我正在粘贴以下客户端代码: 我的理解是uploadify函数中的“script”参数将调用servlet。因此,我在脚本参数中编写了Servlet名称 请告诉我如何进一步进行Java 使用Uploadify时出错,java,jquery,uploadify,Java,Jquery,Uploadify,我是Jquery新手,在使用Uploadify上传文件方面遇到了问题。Iam试图向Java Servlet发送一个文件,该Servlet使用apache commons上传该文件。 但是,在执行代码时,并不是所有的代码都将由servlet完成。实际上,我从web上获取了这个示例并进行了尝试。谁能告诉我我错过了什么?我正在粘贴以下客户端代码: 我的理解是uploadify函数中的“script”参数将调用servlet。因此,我在脚本参数中编写了Servlet名称 请告诉我如何进一步进行 <
<%@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>
谢谢,我刚用了swfupload。。。使用fiddler,我看到我的基本示例只是用uploadify提交了一个文件,所以我放弃了它
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