开发者

How do you access URL text following the # sign through Java?

Using Java (.jsp or whatever) is there a way where I can send a request for this page:

http://www.mystore.com/store/shelf.jsp?category=mens#page=2

and have the Java code parse the URL and see the #page=2 and respond accordingly?

Basically, I'm looking for the Java code that allows me to access the characters following the hash tag.

The reason I'm doing this is that I want to load subsequent pages via AJAX (on my shelf) and then allow the user to copy and paste the URL and send it to a friend. Without the ability of Java being able to read the characters following the hash tag I'm uncertain as to how I would manipulate the URL with Javascript in a way that the server would be able to also read without causing the page to re-load.

I'm having trouble even figuring out how to access/see the entire URL (http://www.mystore.com/store/shelf.jsp?ca开发者_如何学Ctegory=mens#page=2) from within my Java code...


You can't.

The fragment identifier is only used client side, so it isn't sent to the server.

You have to parse it out with JavaScript, and then run your Ajax routines.

If you are loading entire pages (and just leaving some navigation and branding behind) then it almost certainly isn't worth using Ajax for this in the first place. Regular links work better.


Why can't you use a URL like this:

http://www.mystore.com/store/shelf.jsp?category=mens&page=2

If you want the data to be stored in the url, it's gotta be in the query string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜