response.sendRedirect()仅在IE中提供HTTP错误:400 BAD_REQUEST

时间:2011-12-12 23:40:32

标签: java google-app-engine servlets

我正在使用Google App Engine(Java)与Google帐户进行身份验证。

我已经创建了一个servlet(processSignIn.jsp),可以确保允许该帐户出于有效Google帐户以外的原因(邀请已批准等)。如果代码评估正确,它会发出“response.sendRedirect(url)”以将用户发送到“url”参数指定的URL。

如果用户点击此类链接:

<a href="<%= userService.createLoginURL("../processSignIn.jsp?url=" +
request.getRequestURI()) %>">Sign in with a Google Account</a>

然后使用他们的Google帐户登录,一切正常使用Firefox或Chrome,但不适用于IE 9.请参阅下面的请求和回复。

请注意两个GET标头之间的区别...... FF不包含“../”但IE包含。我想继续使用相对路径,所以我不必为本地开发测试做任何奇怪的事情。

可能是什么问题?

Firefox请求:

GET http://www.[mydomain].com/processSignIn.jsp?url=/main.jsp HTTP/1.1
Host: www.[mydomain].com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20100101 Firefox/8.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection: keep-alive
Cookie: [my cookie data]

Firefox响应:

HTTP/1.1 302 Found
Content-Type: text/html
Location: http://www.[mydomain].com/main.jsp
X-AppEngine-Estimated-CPM-US-Dollars: $0.000138
X-AppEngine-Resource-Usage: ms=18 cpu_ms=0 api_cpu_ms=0
Date: Sun, 11 Dec 2011 02:58:06 GMT
Server: Google Frontend
Content-Length: 0

IE 9请求:

GET http://www.[mydomain].com/../processSignIn.jsp?url=/main.jsp HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Pragma: no-cache
Accept-Language: en-US
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
Cookie: [my cookie data]
Accept-Encoding: gzip, deflate
Host: www.[mydomain].com
Connection: Keep-Alive
Cache-Control: no-cache

IE 9回复:

HTTP/1.1 400 Bad Request
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html; charset=iso-8859-1
X-AppEngine-Estimated-CPM-US-Dollars: $0.001025
X-AppEngine-Resource-Usage: ms=13 cpu_ms=32 api_cpu_ms=0
Vary: Accept-Encoding
Date: Sun, 11 Dec 2011 03:00:23 GMT
Server: Google Frontend
Content-Length: 1292

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 400 BAD_REQUEST</title>
</head>
<body>
<h2>HTTP ERROR: 400</h2>
<p>Problem accessing /../processSignIn.jsp. Reason:
<pre>    BAD_REQUEST</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>

1 个答案:

答案 0 :(得分:0)

这只能意味着生成的<a>元素中包含一个/../的URL,其中MSIE和Jetty会阻塞。请注意,您的JSP / servlet代码甚至没有被命中。由于错误的URI,Jetty立即阻止了请求。

要解决错误的URI,请不要将与上下文相关的URL与../一起使用,而应使用与域相关的URL。在您的情况下将是

<a href="<%= userService.createLoginURL(request.getContextPath() 
    + "/processSignIn.jsp?url=" + request.getRequestURI()) %>">

顺便说一句,我想知道userService.createLoginURL()应该做什么。它似乎没什么特别的。