File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes JSP reloads on hash change Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JSP reloads on hash change" Watch "JSP reloads on hash change" New topic

JSP reloads on hash change

Warren Marble

Joined: Oct 13, 2011
Posts: 2

I'm trying to figure out why when I click a link on a jsp with a hash in the URL the jsp is not reloaded, but when modifying the hash using document.location.hash the jsp is reloaded. For example, if I have a link on my page that look like this:

<a href="#index1">index 1</a>

When I click the link the address bar is updated to and the jsp is not reloaded.

Similarly, if I manually edit the URL in the address bar and attach a hash to the end of the URL and hit return, the page is not reloaded.

However; if on some user action I manually update the hash using

location.url.hash = "index1";

The address bar is updated just as before, but the jsp is reloaded in this case.

Actually, reloaded, is not what is happening exactly, because the document onload is not being called; however the jsp is being re-executed. Placing a breakpoint in the jsp verifies this.

This is driving me crazy and screwing up the desired behavior of my site.

I've spent many hours searching for answers, but everything I read indicates that a page does not reload when the hash is updated. I have been unsuccessful in finding any information on the behavior of a jsp in this case.

In all cases I would like the page to behave as if the user clicked a link and not have the jsp re-executed.

Any insight anyone could offer would be greatly appreciated.

W. Marble
Warren Marble

Joined: Oct 13, 2011
Posts: 2

This seems to be a bug with Chrome and Safari. Behavior is as expected on IE, Firefox, and Opera.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

Welcome to the Ranch!

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JSP reloads on hash change
It's not a secret anymore!