2012-10-17 81 views
0

我正在使用BlobStore來保存圖像。我有一個jsp頁面。代號爲頁以下:如何在提交html表單時使用jQuery獲取響應?

<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %> 
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %> 
<% 
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); 
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
    <head> 
    <meta name="description" content="My web page" /> 
    <title>My Web</title> 
    <script type="text/javascript" src="jquery-1.8.0.js"></script> 
    <script src="jquery-mainpage.js"></script> 
    </head> 

<body> 
      <form method="post" id="upload_img_form" name="upload_img_form" action="<%= blobstoreService.createUploadUrl("/imagedao") %>" enctype="multipart/form-data"> 
       <input id="upload_img_form_input" name="upload_img_form_input" type="file"> 
       <input id="upload_img_submit" type="submit" name="upload_img_submit" value="Upload >>" /> 
      </form> 
</body> 
</html> 
在jQuery的mainpage.js

我有以下代碼:

$("#upload_img_form").submit(function(e){ 
     e.preventDefault(); 
     var upload_img_val = $("#upload_img_form_input").val(); 
     if(upload_img_val == ''){ 
       alert('Please choose a file!'); 
     }else{ 
      $.ajax({ 
       type: 'POST', 
       url: url_to_blobstore, 
       data: {upload_img_form_input:upload_img_val}, 
       success: function(result) { 
       console.log('upload_img_form result: '+result); 
      } 
     }); 
     } 
}); 

我得到以下異常:

java.lang.OutOfMemoryError: Java heap space 
at java.util.Arrays.copyOf(Arrays.java:2786) 
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:71) 
at javax.mail.internet.MimeMultipart.readTillFirstBoundary(MimeMultipart.java:244) 
at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:181) 
at javax.mail.internet.MimeMultipart.getCount(MimeMultipart.java:109) 
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.handleUpload(UploadBlobServlet.java:145) 
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.access$000(UploadBlobServlet.java:68) 
at com.google.appengine.api.blobstore.dev.UploadBlobServlet$1.run(UploadBlobServlet.java:111) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.doPost(UploadBlobServlet.java:108) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166) 
at com.google.appengine.tools.appstats.AppstatsFilter.doFilter(AppstatsFilter.java:141) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97) 
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418) 
at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94) 

我爲什麼得到這個例外。代碼有問題嗎? 我想在提交此表單時獲得回覆。所有的jQuery代碼都在jquery-mainpage.js中。有沒有可以給我回應的jQuery方法?

在此先感謝。

+1

有一些jQuery文件上傳插件。使用其中之一..很容易找到在谷歌 – charlietfl

+0

你是什麼意思的「響應」?如果你在談論頁面響應,那麼這是不可能的,因爲頁面重新加載。如果你正在談論響應sumbit事件,只需添加一個提交處理程序。 – jbabey

回答

相關問題