简体   繁体   English

如何从Java Servlet访问重定向的URL?

[英]How do I access a redirected url from my java servlet?

Hey guys, I've started doing some work on servlets, and I need to implement a facebook login for one of my projects. 大家好,我已经开始在servlet上做一些工作,我需要为我的一个项目实现facebook登录。 I created a dummy app on facebook, and I am using restfb for this. 我在Facebook上创建了一个虚拟应用程序,为此我正在使用restfb。 First I redirect the user to 首先,我将用户重定向到

https://graph.facebook.com/oauth/authorize?client_id=[MY_APP_ID]&display=page&redirect_uri=[MY_WEBPAGE]&scope=[PERMISSIONS_MY_APP_IS_ASKING_FOR] https://graph.facebook.com/oauth/authorize?client_id=[MY_APP_ID]&display=page&redirect_uri=[MY_WEBPAGE]&scope=[PERMISSIONS_MY_APP_IS_ASKING_FOR]

to get permission, and if the user clicks allow, then facebook redirects the user to [MY_WEBPAGE]/?code=XXXX, and I need to be able to have access to whatever comes after code. 要获得许可,并且如果用户单击允许,那么Facebook会将用户重定向到[MY_WEBPAGE] /?code = XXXX,我需要能够访问代码后面的所有内容。 How would I fetch the part after "code" in a servlet? 如何在Servlet中的“代码”之后获取部分?

Thanks 谢谢

您应该能够执行类似String code = req.getParameter("code");

If I remember correctly, you can't do itn because your [WEB_PAGE] should end with "/" character. 如果我没记错的话,您将无法执行此操作,因为您的[WEB_PAGE]应该以“ /”字符结尾。 What I have done is to map my servlet (let's call facebook) as /facebook/* and then set code as /facebook/XXXX/ 我要做的是将我的servlet(让我们称为facebook)映射为/ facebook / *,然后将代码设置为/ facebook / XXXX /

After it you can grab this URI and extract your XXXX value and assign it as to code variable. 之后,您可以获取此URI并提取您的XXXX值,并将其分配为code变量。

Hope it Help. 希望对您有所帮助。 If you are using Spring MVC framework then you can do it as 如果您使用的是Spring MVC框架,则可以按照

@RequestMapping(value="/facebook/{code}")
public List<Category> facebookapp(@PathVariable String code,Model){
////
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM