bishnu
bishnu

Reputation: 21

Jumping to anchors in JSP

When jumping to anchors on a JSP, HTML anchors do not work. Eg, something like

<a href="#name">Link</a>
...
<div id="name"></div>

fails because the server actually looks for a file named "filename.jps#name" and returns an error. Is there any workaround for this?

Upvotes: 2

Views: 4479

Answers (2)

andyb
andyb

Reputation: 43823

What you describe is called a fragment identifier and the target can be a named anchor or an identified element, for example

<a href="#foo">go to foo</a>
<a name="foo">foo</a>
<div id="foo">foo</div>

with the named anchor variation demonstrated in this demo

Please also note that the HTML5 specification has deprecated the name attribute for a elements has been dropped, so an id would be the only HTML5 valid way to navigate to a fragment identifier.

Upvotes: 1

BalusC
BalusC

Reputation: 1109132

I think that you've set a <base> tag in your document. All identifier links are also relative to it. If this is true, then you need to change your identifier links from

<a href="#name">

to

<a href="${pageContext.request.requestURI}#name">

See also:

Upvotes: 0

Related Questions