简体   繁体   中英

Struts2 redirecting urls having hash

I am currently implement a facebook login in my application, after the user has successfully authorized his or hers account, it would go back to an action class in my web server and on that.

Here's an example

1)User clicks logged in with facebook 2)He or she will be redirected to this facebook authorization page 2) Once he or she has been authorized.the page will then be redirected to struts2 action class. so the url will be looked like this

http://127.0.0.1:8080/MyApp-Facebook/oAuthExchange?code=SomeLongFacebookCodHere#_=_

if you will see the ending url of oAuthExchange has a #_=_ . and then it will be redirected to the dashboard page of my app the page url will looked like this

http://127.0.0.1:8080/Struts2-Facebook/dashboard#_=_

if you'll notice there is a "#_=_" in my URL. is there anyway I can remove the "#_=_" when I do a redirect?

I am also using Facebook4j for facebook graph API

You can remove it directly from the result page in HTML5 compliant Browsers with history.pushState() .

Assuming #_=_ is fixed (otherwise you need to perform a dynamic substring with indexOf looking for # ), put this in your page:

<script>
    //4 is the lenght of #_=_
    var cleanLocation = location.href.substring(0, location.href - 4); 
    history.pushState("","", cleanLocation);
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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