在我的 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>
当我第一次加载到这个 jsp 页面时,一切正常。单击任何链接的那一刻,我将收到以下错误。
java.io.IOException: Server returned HTTP response code: 400 for URL: https://graph.facebook.com/oauth/access_token?client_id=xxx&scope=user_photos&redirect_uri=http://xxx.herokuapp.com/test&client_secret=xxx&code=xxx
我想知道这个错误是否与我的查询字符串有关?有没有办法解决这个问题,因为我真的需要在我的 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