Jsp 服务器为URL返回了HTTP响应代码:400
在我的jsp页面中,我有包含不同查询字符串的链接。我使用它主要是为了分页Jsp 服务器为URL返回了HTTP响应代码:400,jsp,exception,query-string,paging,Jsp,Exception,Query String,Paging,在我的jsp页面中,我有包含不同查询字符串的链接。我使用它主要是为了分页 <a href='/test?page=1&code=${code}'>Page 1</a> <a href='/test?page=2&code=${code}'>Page 2</a> <a href='/test?page=3&code=${code}'>Page 3</a> 我想知道这个错误是否与我的查询字符串有关?有没
<a href='/test?page=1&code=${code}'>Page 1</a>
<a href='/test?page=2&code=${code}'>Page 2</a>
<a href='/test?page=3&code=${code}'>Page 3</a>
我想知道这个错误是否与我的查询字符串有关?有没有办法解决这个问题,因为我真的需要jsp页面中的分页
在我的servlet中
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String code = req.getParameter("code");
String page = req.getParameter("page");
if(page == null){
page = "1";
}
String MY_ACCESS_TOKEN = "";
String redirect = "http://xxx.herokuapp.com/test";
String en_redirect = URLEncoder.encode(redirect, "UTF-8");
String en_code = URLEncoder.encode(code, "UTF-8");
String authURL = "https://graph.facebook.com/oauth/access_token?client_id=xxx&scope=user_photos&redirect_uri=" + en_redirect + "&client_secret=xxx&code="
+ code;
URL url = new URL(authURL);
String result = readURL(url);
String[] pairs = result.split("&");
for (String pair : pairs) {
String[] kv = pair.split("=");
if (kv[0].equals("access_token")) {
MY_ACCESS_TOKEN = kv[1];
}
} // end of for loop
您需要对参数redirect_uri的值进行HTML编码。这是将特殊字符转换为%后跟十六进制数的过程。就像空间变成了%20。这对于编码第二个URL(而不是主URL)中的符号非常重要
parameter = java.net.URLEncoder.encode( parameter );
对所有参数都这样做是一种很好的做法,尤其是当它们可能包含一个符号时。我已将其添加到现有代码中,但仍然会得到相同的错误。我在第一篇文章中更新了代码,我是否遗漏了什么?谢谢
parameter = java.net.URLEncoder.encode( parameter );