我正在創建一個需要圖片上傳功能的應用程序。我一直在遵循this教程和App Engine Documentation。GAE和GWT - response.sendRedirect不重定向
圖像上傳正確,服務器重定向到FileUpload HttpServlet的doPost函數。我可以從請求中讀取blob密鑰並將其保存在數據存儲中。
我的問題是發回一個響應給客戶端。我見過的所有東西都指向使用response.sendRedirect函數,但尚未成功。
public class FileUpload extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
Map<String, List<BlobKey>> blobs = blobstoreService.getUploads(request);
BlobKey blobKey = blobs.get("picFileUpload").get(0);
ShipHull shipHull = new ShipHull();
shipHull.setShipHullName(request.getParameter("hullNameText"));
shipHull.setShipImageURL("/shipbuilder/blobService?blob-key=" + blobKey.getKeyString());
PersistenceManager pm = PMF.get().getPersistenceManager();
try
{
pm.makePersistent(shipHull);
}
catch (Exception e)
{
String hi = "hello";
}
finally
{
pm.close();
}
Boolean test = response.isCommitted();
response.sendRedirect("/shipbuilder/FileUpload?gwt.codesvr=127.0.0.1:9997&shipHullName=" + shipHull.getShipHullName());
test = response.isCommitted();
return;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException
{
String id = req.getParameter("shipHullName");
resp.setHeader("Content-Type", "text/html");
resp.getWriter().println(id);
}
}
我正試圖將客戶端重定向到這個servlet中的doGet。我已經嘗試過,沒有gwt.codesvr=127.0.0.1:9997
和shipHullName=" + shipHull.getShipHullName())
,但doGet函數永遠不會到達。我也試過https://www.google.com
。
這是在開發服務器上完成的所有事情(尚未在生產服務器上嘗試過)。
如果您有任何其他方法返回圖像保存的狀態(如已經採取了文件名),我不介意嘗試不同的東西。
謝謝!
你有任何運氣與建議? – SSR