2

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
bishnu
  • 21
  • 1
  • 2

2 Answers2

1

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.

andyb
  • 43,435
  • 12
  • 121
  • 150
  • *Must*? Wrong. An element ID is also perfectly valid. See http://jsfiddle.net/NTSjt/ – BalusC Nov 08 '11 at 00:29
  • Nice spot thanks @BalusC. I have updated my answer. I also remembered that anchor `name` is deprecated in HTML5. – andyb Nov 08 '11 at 06:47
0

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:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555