1

当我blobstore upload form JSP使用 jQuery Mobile 1.3.0. 我在下面发布代码。

<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css" />
<link rel="stylesheet" href="/css/common.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script>
</head>
<body>
 <%
   BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
 %>
 <form method="POST" action="<%=blobstoreService.createUploadUrl("/upload")%>"
  id="uploadImageForm" enctype="multipart/form-data">
    <label for="newsTitle">New Title</label>
    <input type="text" name="newsTitle" id="newsTitle" placeholder="Please enter some title" />
    <div style="clear: both; width: 100%;"></div>

    <label for="newsDescription">New Description</label>
    <textarea name="newsDescription" id="newsDescription" placeholder="Please enter some description" rows="10"></textarea>
    <div style="clear: both; width: 100%;"></div>

    <label for="newsPic">Choose Image (if any)</label>
    <input type="file" name="newsPic" id="newsPic" class="newsPic" />
    <div style="clear: both; width: 100%; height: 10px;"></div>

    <input type="submit" name="submit" data-role="button" data-inline="true" value="Submit" />
  </form>
</body>

当我尝试通过此表单将任何文件上传到 blobstore 时,出现此异常。

WARNING: Error for /_ah/upload/agpsdW1paW5uZXdzchsLEhVfX0Jsb2JVcGxvYWRTZXNzaW9uX18YOAw
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:245)
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:146)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.access$000(UploadBlobServlet.java:69)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet$1.run(UploadBlobServlet.java:112)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.appengine.api.blobstore.dev.UploadBlobServlet.doPost(UploadBlobServlet.java:109)
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.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:110)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
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)

当我尝试使用普通的 css 和 jquery 库使用简单的 JSP 页面上传时,一切正常。

<%@ page
import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>News App : Upload New News</title>

 <link href="/bootstrap/css/bootstrap-responsive.css" type="text/css"
rel="stylesheet" />
 <link href="/bootstrap/css/bootstrap.css" type="text/css"
rel="stylesheet" />
 <script src="http://code.jquery.com/jquery-1.8.2.min.js"
type="text/javascript"></script>
 <script src="/bootstrap/js/bootstrap.js" type="text/javascript"></script>
</head>
<body>
<%
    BlobstoreService blobstoreService = BlobstoreServiceFactory
            .getBlobstoreService();
%>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span1"></div>
        <div class="span10">
            <ul class="nav nav-tabs">
                <li><a href="/">Home</a></li>
                <li class="active"><a href="/newpost">Post New Topic</a></li>
            </ul>
            <form method="POST"
                action="<%=blobstoreService.createUploadUrl("/upload")%>"
                id="uploadImageForm" enctype="multipart/form-data">
                <fieldset>
                    <legend class="text-info">Upload Form</legend>
                    <label for="newsTitle">News Title</label> <input type="text"
                        name="newsTitle" id="newsTitle" class="span12"
                        placeholder="Type some title..." />
                    <div class="clear"></div>
                    <label for="newsDescription">News Description</label>
                    <textarea class="textarea span12" name="newsDescription"
                        id="newsDescription" placeholder="Type some description..."
                        style="height: 70px;"></textarea>
                    <div class="clear"></div>
                    <label for="newsPic">Choose Picture</label> <input type="file"
                        name="newsPic" id="newsPic" placeholder="Type some title..." />
                    <div class="clear"></div>
                    <input type="submit" class="btn btn-success" value="Submit" />
                </fieldset>
            </form>
        </div>
        <div class="span1"></div>
    </div>
</div>

根本无法理解为什么会出现这个问题。我需要你的建议。

4

2 回答 2

2
于 2013-02-23T20:40:01.840 回答
1

I suspect Tolis has the answer on this, so I'll take a shot at the "I need your suggestions" part.

This is the kind of problem where it really helps to reduce the failure to the smallest possible test case (or at least a smaller test case than this). This helps in several ways: First, it'll often lead you to seeing the otherwise hard-to-spot typo that you might have made. (If I had a nickel for every time I accidentally typed "multipart/form-date"... But that's hard to spot when there's lots of extra clutter.)

Second, by eliminating distractions, it helps the people who are trying to help you by giving them less irrelevant stuff to wade through.

Third, if you do find a bug, a simple test case greatly improves the chance that it'll get fixed quickly.

In this particular case, I seriously doubt that either spring or css have anything to do with the behavior you're seeing. The non-file input fields could also go, unless they change the behavior you're seeing.

于 2013-02-24T04:02:52.703 回答