答案 0 :(得分:12)
我发现了自己的错误!因为它突然失败的原因是因为FORM帖子认为它是跨域发布。我通过调用127.0.0.1:8888..etc来测试网站但是当我的Image RPC被调用以建立上传路径时,它返回到表单setAction我的机器名称kmoore-PC:8888..etc而不是127.0.0.1:8888 ...因此它返回null因为它认为它是跨域。
要修复此问题,请点击网址栏中的Google框并添加您的计算机名称,然后使用计算机名称而不是127来测试您的应用
答案 1 :(得分:0)
我尝试用机器名替换本地主机它没有帮助,但它是一个跨域java脚本问题,所以我尝试使用web xml中指定的URL模式,我得到了一个String结果。结果是我的回复包含了XML,我打算解析它。如果有人有更优雅的东西请告诉我。
这里是响应String [它看起来有点不同,因为它会影响堆栈溢出页面]:
pre style =“word-wrap:break-word; white-space:pre-wrap;”> my response id
以下是相关的服务器代码
public void doPost(HttpServletRequest request,HttpServletResponse response)抛出> ServletException,IOException { //递归重定向到此servlet(调用doGet) response.sendRedirect(“/ blobstoreexample / uploadservice?id =”+> item_image_blob_key); } }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException { System.out.println("shonka"); //Send the meta-data id back to the client in the HttpServletResponse response String id = req.getParameter("id"); response.getWriter().write(id); return; }
这是相关的客户端代码,这里不需要解析服务器端代码:
uploadForm.addSubmitCompleteHandler(new FormPanel.SubmitCompleteHandler() {
@Override
public void onSubmitComplete(SubmitCompleteEvent event) {
//The submit complete Event Results will contain the unique
//identifier for the picture's meta-data. Trim it to remove
//trailing spaces and line breaks
System.out.println("uploadForm onSubmitComplete() results are: " + event.getResults());
Window.alert(event.getResults());
if(event.getResults() != null)
{
// getPicture(event.getResults().trim());
}
else
{
Window.alert(event.getResults());
}
}
});
编辑我找到了一种更优雅的方式来提供长身份
//Redirect recursively to this servlet (calls doGet)
response.sendRedirect("/itemmanager/receive?id=" + item.getKey().getId());
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
System.out.println("entered do post");
//Send the meta-data id back to the client in the HttpServletResponse response
String id = req.getParameter("id");
System.out.println("entered do post id is: " + id);
resp.setHeader("Content-Type", "text/html");
resp.getWriter().println(id);
}
答案 2 :(得分:0)
在开发模式下,我只需将其替换为127地址,而不是使用计算机名称,如下所示:
String url = blobstoreService.createUploadUrl("/project/uploadservice");
// change the computer name to standard localhost ip address, if in dev mode
if(SystemProperty.environment.value() == SystemProperty.Environment.Value.Development)
{
url = url.replace("Your-PC-Name", "127.0.0.1");
}