• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

forward to jsp not working when trying to use HTML's *a name* link

 
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some standard code for forwarding to a JSP from within a servlet:



That method is called like this:



I have that #shortcut on the end of the path because in the HTML on that page I have an anchor like this:



Nothing strange--I just want the browser the browser to scroll down the page to that point so the user doesn't have to keep on doing that. I can easily do this with a couple of barebones HTML pages, but I'm guessing the servlet or RequestDispatcher doesn't like that pound sign, because whenever it tries to forward there I just get an HTTP 404 error ("The page cannot be found");

Is there any way I can get around this, or is there a way to get the browser to jump to that spot based on something in the HTML (something I can dynamically stick into onLoad, perhaps?). Thanks...
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
'forward' happens on the server and indicates that another resource will fill the request.

'#' happens in the client (in the browser) and jumps to a tag in the page.

The two aren't compatible. You may find that sendRedirect is what you are looking for. It sends a message to the client asking them to request the resource indicated, and should support the 'hash' too.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, sendRedirect works, but then I lose my original request parameters. That's why I wanted to use forward. No chance there's a way to make the Java code in the JSP spit out some HTML that will cause the browser to skip down to the name when the page is loaded...?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only if the anchor was in the request url that was last sent from the browser.



With a server side forward the URL never gets re-written. There is only one request being made from the browser to the server.
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic