Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序引擎HTTP状态代码消息_Java_Google App Engine_Http Status Code 400 - Fatal编程技术网

Java 应用程序引擎HTTP状态代码消息

Java 应用程序引擎HTTP状态代码消息,java,google-app-engine,http-status-code-400,Java,Google App Engine,Http Status Code 400,我发现Java的dev_appserver与live App Engine服务器之间存在不一致 在本地开发服务器上,我有一个Servlet,它返回: return response.sendError(response.SC_BAD_REQUEST, "Please log in to comment"); 当我访问页面时,我会在标题中返回一条状态代码消息,它是: Status Code:400 Please log in to comment 当我将其部署到应用程序引擎时,问题就出现了。当

我发现Java的
dev_appserver
与live App Engine服务器之间存在不一致

在本地开发服务器上,我有一个Servlet,它返回:

return response.sendError(response.SC_BAD_REQUEST, "Please log in to comment");
当我访问页面时,我会在标题中返回一条状态代码消息,它是:

Status Code:400 Please log in to comment
当我将其部署到应用程序引擎时,问题就出现了。当访问同一个servlet时,我得到的是“错误请求”,而不是“请登录以发表评论”:

请登录到comment
状态代码消息显示在内容HTML中,但不会像在开发环境中那样显示在标题中

为什么会这样

编辑

以下是针对dev_appserver和生产的
curl-vvv
跟踪:

dev_appserver curl跟踪:

> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
>         
< HTTP/1.1 400 Please log in to comment
< Content-Type: text/html; charset=iso-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1406
< Server: Jetty(6.1.x)
> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: www.xxx.org
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Date: Thu, 18 Aug 2011 14:04:26 GMT
< Server: Google Frontend
< Cache-Control: private
< Transfer-Encoding: chunked
>发布/添加评论HTTP/1.1
>用户代理:Mozilla/4.0
>主机:本地主机:8080
>接受:*/*
>内容长度:9
>内容类型:application/x-www-form-urlencoded
>         
生产卷曲跟踪:

> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: localhost:8080
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
>         
< HTTP/1.1 400 Please log in to comment
< Content-Type: text/html; charset=iso-8859-1
< Cache-Control: must-revalidate,no-cache,no-store
< Content-Length: 1406
< Server: Jetty(6.1.x)
> POST /add-comment HTTP/1.1
> User-Agent: Mozilla/4.0
> Host: www.xxx.org
> Accept: */*
> Content-Length: 9
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 400 Bad Request
< Content-Type: text/html; charset=utf-8
< Vary: Accept-Encoding
< Date: Thu, 18 Aug 2011 14:04:26 GMT
< Server: Google Frontend
< Cache-Control: private
< Transfer-Encoding: chunked
>发布/添加评论HTTP/1.1
>用户代理:Mozilla/4.0
>主持人:www.xxx.org
>接受:*/*
>内容长度:9
>内容类型:application/x-www-form-urlencoded
> 
我认为prod系统是正确的实现方式。
sendError()
的javadocs说:

使用指定的状态向客户端发送错误响应最新版本 服务器默认创建的响应看起来像 包含指定消息的HTML格式服务器错误页, 将内容类型设置为“text/html”,保留cookie和其他 标题未修改。如果已为的错误页面声明 与传入的状态代码对应的web应用程序,它将 优先于建议的msg参数返回

如果响应已经提交,此方法将抛出 非法国家例外。使用此方法后,响应应为 视为已承诺,不应写信给


我突出了一部分。这表示它只在可能的情况下返回包含消息的html页面。它没有说它在HTTP状态代码中使用它(我个人在任何地方也没有看到过:()这并不是
sendError
的具体问题。
setStatus
方法将以相同的方式运行。在普通Java中,
sendError
setStatus
都会设置状态描述。问题是,生产应用程序引擎服务器总是将状态描述设置为r每个代码。

你能为devappserver和production这两个调用添加curl-vvv跟踪吗?很有趣。看起来你是对的。关于状态代码消息没有任何说明。Jetty(dev_appserver)似乎将其显示为HTTP状态消息,但其他人可能不会。我想知道是否有办法在应用程序引擎环境中强制显示它-我想人们可以在标题中设置自己的状态消息。