Google app engine GAE和GWT-response.sendRedirect不是重定向
我正在创建一个需要图像上传功能的应用程序。我一直在遵循教程和 映像已正确上载,服务器被重定向到FileUpload HttpServlet的doPost函数。我可以从请求中读取blob密钥并将其保存在数据存储中 我的问题是将响应发送回客户端。我所看到的一切都指向使用response.sendRedirect函数,但这还没有成功Google app engine GAE和GWT-response.sendRedirect不是重定向,google-app-engine,gwt,blobstore,Google App Engine,Gwt,Blobstore,我正在创建一个需要图像上传功能的应用程序。我一直在遵循教程和 映像已正确上载,服务器被重定向到FileUpload HttpServlet的doPost函数。我可以从请求中读取blob密钥并将其保存在数据存储中 我的问题是将响应发送回客户端。我所看到的一切都指向使用response.sendRedirect函数,但这还没有成功 public class FileUpload extends HttpServlet { public void doPost(HttpServletRequest
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);
}
}
公共类文件上载扩展了HttpServlet
{
public void doPost(HttpServletRequest请求,HttpServletResponse响应)抛出ServletException,IOException
{
BlobstoreService BlobstoreService=BlobstoreServiceFactory.getBlobstoreService();
Map blobs=blobstoreService.getUploads(请求);
BlobKey-BlobKey=blobs.get(“picFileUpload”).get(0);
ShipHull ShipHull=新ShipHull();
shipHull.setShipHullName(request.getParameter(“hullNameText”));
shipHull.setShipImageURL(“/Shippuilder/blobService?blob key=“+blobKey.getKeyString());
PersistenceManager pm=PMF.get().getPersistenceManager();
尝试
{
项目经理(船体);
}
捕获(例外e)
{
String hi=“你好”;
}
最后
{
pm.close();
}
布尔测试=response.isCommitted();
response.sendRedirect(“/shippuilder/FileUpload?gwt.codesvr=127.0.0.1:9997&shipHullName=“+shipHull.getShipHullName());
test=response.isCommitted();
返回;
}
@凌驾
受保护的void doGet(HttpServletRequest-req、HttpServletResponse-resp)引发IOException
{
字符串id=req.getParameter(“shipHullName”);
相应的setHeader(“内容类型”、“文本/html”);
resp.getWriter().println(id);
}
}
我试图将客户机重定向回同一个servlet中的doGet。我尝试过这个,没有使用gwt.codesvr=127.0.0.1:9997
和shipHullName=“+shipHull.getShipHullName())
,但从未使用过doGet函数。我也尝试过https://www.google.com
这一切都是在开发服务器上完成的(尚未在生产服务器上尝试)
如果您有任何其他返回图像保存状态的方法(例如,如果文件名已被占用),我不介意尝试其他方法
谢谢!您可以尝试将成功/失败的字符串放入resp对象中吗
public void doPost( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException
{
try{
processFileUploads(req)
resp.getWriter().print( "Success" );
}{
catch(Exception e){
resp.getWriter().println( "Unable to upload the file - Upload Failed" );
}
}
我已经解决了这个问题。我想我和你有同样的问题 我必须点击GWT开发模式工具箱图标,添加Web服务器“ammo box”(我的计算机名称)和代码服务器“127.0.0.1”。当我将浏览器指向该开发链接时,一切正常,甚至你给出的SSR答案也正常。这是一个域切换问题
谢谢你的帮助。你对这个建议有什么看法吗?很抱歉,我反应太慢了,但是我尝试过。当我使用writer时,客户端仍然看到一个空响应。我感觉这是blobstore的一些特殊行为,因为它是从另一个服务器进程转发到此post servlet的。我将发布我下一次得到的客户机代码。也许这也能提供一些信息。您可以通过选择您的答案来关闭查询。如果您觉得其他答案有帮助,请投票:)。保持堆垛溢出物清洁。