验证成功后,facebook重定向到facebookConnected.jsp。我希望它被重定向到主页。如何实现?我尝试使用控制器进行重定向,但效果不佳。
答案 0 :(得分:0)
在 ConnectController 中,你有这些方法
/**
* Returns the view name of a page to display for a provider when the user is connected to the provider.
* Typically this page would allow the user to disconnect from the provider.
* Defaults to "connect/{providerId}Connected". May be overridden to return a custom view name.
* @param providerId the ID of the provider to display the connection status for.
*/
protected String connectedView(String providerId) {
return getViewPath() + providerId + "Connected";
}
/**
* Returns a RedirectView with the URL to redirect to after a connection is created or deleted.
* Defaults to "/connect/{providerId}" relative to DispatcherServlet's path.
* May be overridden to handle custom redirection needs.
* @param providerId the ID of the provider for which a connection was created or deleted.
* @param request the NativeWebRequest used to access the servlet path when constructing the redirect path.
*/
protected RedirectView connectionStatusRedirect(String providerId, NativeWebRequest request) {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
String path = "/connect/" + providerId + getPathExtension(servletRequest);
if (prependServletPath(servletRequest)) {
path = servletRequest.getServletPath() + path;
}
return new RedirectView(path, true);
}
具体而言,他们说可以覆盖方法来获取我们的特定重定向网址。但老实说,我不知道如何压倒他们。我想你可以创建一个新的@Config类来扩展它并覆盖@RequestMapping(" / connect")。
如果您知道某种方式,请写在这里,因为我处于相同的情况,因为我使用Spring Webflow,我想保持流程。
在我的案例中,控制器 /WEB-INF/connect/facebookConnected.xhtml 将在ExternalContext中找不到作为资源,因为我将我的应用配置为在文件夹中查找/ WEB-INF /流动。
答案 1 :(得分:0)
我遇到了同样的问题,我通过覆盖ConnectController类来解决问题
@Controller
@RequestMapping("/connect")
public class CustomController extends ConnectController {
public CustomController(ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
@Override
protected String connectedView(String providerId) {
return "redirect:/facebook";
}
}
此链接有more explanation about how to change the default spring social redirect flow。