开发者

How to pass authorization code from JSP to Servlet

I am at my wits end, 7 hours and counting.

I am new to FB development and am having an issue of passing the authorization code from my JSP to my Servle开发者_如何学Pythont.

1.) I use the social plugin for login in my JSP as shown below

<fb:login-button>Login with Facebook</fb:login-button>

This logs the user in and allows them to grant my app access to their personal information

2.) Once login and authorization are successful, the user is forwarded to my servlet from the JSP via the code below

 FB.Event.subscribe('auth.login', function (response) {
 window.location = "testservlet"; 
 });

3.) But when I attempt to get the authorization code (so that I can get the auth. token) in my Servlet, the "code" is empty, see the code I am using to retrieve below

String authCode = req.getParameter("code");

Can anyone tell me what I am doing wrong? I am sure that I am missing something so simple..or am trying to do more than is necessary, thanks in advance


I am not familiar with Facebook dev, but concerning servlets, window.location normally speaking will not take you to a servlet.
try using jquery's ajax function and pass a "code" parameter. Do something like :

$.ajax({
        url: yourServletPath+"testservlet",
        data:"code="+codevariable,
        dataType: "whatever data type your servlet returns",
        success: function(response) 
        {
          // wtv code to be done
        } 
      });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜