Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • 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...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
  • 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...?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic