Google App Engine Blobstore图片

问题描述 投票:1回答:1

我正在尝试创建一个简单的Web应用程序,以使用Blobstore上传多个图像。 我已成功将图像成功上传到Blobstore。 但是,当图像上载时,用于上载的servlet不会重定向到我尝试将其重定向到的任何页面。 IT只是显示一个空白页面,其URL如下:myapplicationId.appstore.com/_ah/upload/.…(键值)

我无法更改名为“上传到另一个页面”的servlet的重定向。 我也尝试提供图像,但是无法做到。

有人可以指导我吗?

我正在使用Java中Google的标准代码上传图像。

我的JSP是:

<%@ page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory" %>
<%@ page import="com.google.appengine.api.blobstore.BlobstoreService" %>
 <script>
<%
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

%>

</script>
<html>
<head>
<title>Show My Picture(s)</title>
</head>
<body>

<h1>Show My Picture(s)</h1>
<hr/>
<h2>Upload picture(s)</h2>
<form action="<%= blobstoreService.createUploadUrl("/upload") %>" method="post" enctype="multipart/form-data">
Upload File(s) :
<input type="text" name="filename"/>
<input type="file" name="myPics" multiple="multiple"/>
<input type="submit" value="Upload Picture"/>
</form>
</html>

我的上载Servlet:

package photos;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import photos.Upload;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

/**
 * Servlet implementation class Upload
 */
@WebServlet("/Upload")
public class Upload extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    private final static Logger _logger = Logger.getLogger(Upload.class.getName());
    private BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();

    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {

            try{
            Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
            BlobKey blobKey = blobs.get("myPics");


            if (blobKey == null) {
                res.sendRedirect("/");
            }
            else {
                res.sendRedirect("/upload?blob-key="+blobKey.getKeyString()+"blobSize="+blobs.size());
              }
            }catch(Exception e){
                e.printStackTrace();
                System.out.println("Document failed to POST, redirecting back to upload.");
                res.sendRedirect("/index.jsp");
            }
    }

    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {

        String uploadedImageKey = req.getParameter("blob-key");
        PrintWriter out = resp.getWriter();
        resp.setHeader("Content-Type", "text/html");
        resp.sendRedirect("/viewPics.jsp");
        //out.println(req.getParameter("blobSize")+" images have been successfully uploaded");



    }
}

我要去哪里错了?

java google-app-engine jsp servlets blobstore
1个回答
0
投票

我想自助是最好的帮助。 我解决了这个问题。 只是将上载更改为createUploadUrl中的Upload。

© www.soinside.com 2019 - 2024. All rights reserved.