我刚刚开始使用Uploadify Flash插件而不是标准HTML UI。 并遇到了下一个问题:
当我单击“上传文件”链接时,将显示进度并显示“已完成”状态,但实际上-并未发生任何事情,因此未从后端调用Java Servlet。
有上传的servlet和上传下一个方式执行 早先 :
< form enctype="multipart/form-data" method="post" target="uploadFrame" action="<%= request.getContextPath() %>/uploadFile?portletId=${portletId}&remoteFolder=${remoteFolder}">...
提供Uploadify插件后,UI 现在 如下所示:
插件部分(配置):
<script> ... oScript.text+= "$j('#uploadify').uploadify({"; oScript.text+= "'uploader' : 'kne-portlets/js/lib/uploadify/scripts/uploadify.swf',"; oScript.text+= "'script' : '<%= request.getContextPath() %>/uploadFile?portletId=${portletId}&remoteFolder=<%= decodedString %>',"; oScript.text+= "'cancelImg': 'kne-portlets/js/lib/uploadify/cancel.png',"; oScript.text+= "'folder' : '<%= decodedString %>',"; oScript.text+= "'queueID' : 'fileQueue',"; oScript.text+= "'auto' : false,"; oScript.text+= "'multi' : false,"; //oScript.text+= "'sizeLimit' : 1000"; oScript.text+= "});"; oScript.text+= "});"; ... </script>
这里的’scripts’参数指向后端的Java Servlet
<%= decodedString %>是文件夹路径,其值为 \\ file-srv \ demo
<%= decodedString %>
上传部分:
<input type="file" name="uploadify" id="uploadify" /> <a href="javascript:$j('#uploadify').uploadifyUpload();">Upload Files</a>
我的错在哪里
插件配置中的“脚本”参数指向后端的Java Servlet,此操作已完成,但未触发Servlet。
错误,如果“脚本”参数不正确:http : //img190.imageshack.us/i/errormm.png/
感谢您的协助。
这可能有很多可能的原因(另请参阅我发表的评论)。
url-pattern
很难根据现有信息确定根本原因。
正如您提到的那样,您没有在FireBug的“网络”选项卡中看到任何请求被触发,我认为JS代码在语法/逻辑上完全无效。右键单击页面,然后双重验证生成/打印的JS代码。
更新: 我试图重现您的问题。
我下载了jquery.uploadify-v2.1.0(MIT),将其解压缩并将所有内容/WebContent/uploadify放入Eclipse中我的(空)操场Web项目的文件夹中。
/WebContent/uploadify
我创建了一个/WebContent/upload.jsp文件,如下所示:
/WebContent/upload.jsp
<!DOCTYPE html> <html lang="en"> <head> <title>Uploadify test</title> <script src="uploadify/jquery-1.3.2.min.js"></script> <script src="uploadify/swfobject.js"></script> <script src="uploadify/jquery.uploadify.v2.1.0.min.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#uploadify').uploadify({ 'uploader': 'uploadify/uploadify.swf', 'script': 'uploadServlet', 'folder': '/uploads', 'cancelImg': 'uploadify/cancel.png' }); $('#upload').click(function() { $('#uploadify').uploadifyUpload(); return false; }); }); </script> </head> <body> <input id="uploadify" type="file"> <a id="upload" href="#">Upload</a> </body> </html>
com.example.UploadServlet
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
/WEB-INF/lib
package com.example; import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public class UploadServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("UploadServlet invoked. Here are all uploaded files: "); try { List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : items) { if (!item.isFormField()) { System.out.println("Name: " + item.getName()); System.out.println("Size: " + item.getSize()); System.out.println("Type: " + item.getContentType()); } } } catch (Exception e) { throw new ServletException(e); } } }
web.xml
<servlet> <servlet-name>uploadServlet</servlet-name> <servlet-class>com.example.UploadServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>uploadServlet</servlet-name> <url-pattern>/uploadServlet</url-pattern> </servlet-mapping>
Upload
UploadServlet被调用。这是所有上传的文件:
名称:glassfish-v3-windows.exe 尺寸:50402555 类型:应用程序/八位字节流
很抱歉,我无法重现您的问题。至少,以上信息应该可以帮助您“重新开始”。希望能帮助到你。
更新: 根据评论,过滤器期望它正在使用相同的会话。好的,您可以通过更改
'<%= request.getContextPath() %>/uploadFile?portletId=${portletId}&remoteFolder=<%= decodedString %>',";
至
'<%= request.getContextPath() %>/uploadFile;jsessionid=${pageContext.session.id}?portletId=${portletId}&remoteFolder=<%= decodedString %>',";