wood burning stoves*
The moose likes Servlets and the fly likes forward to jsp not working when trying to use HTML's *a name* link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "forward to jsp not working when trying to use HTML Watch "forward to jsp not working when trying to use HTML New topic
Author

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

Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
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

Joined: Mar 06, 2001
Posts: 13459

'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

Joined: Jul 15, 2003
Posts: 618
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: forward to jsp not working when trying to use HTML's *a name* link
 
Similar Threads
Can i call a servlet from within a JSP and return immediately?
Newbie: Need help with checkbox post parameters
RequestDispatcher working, but ultimately sends an empty HTML page to client
help with jquery ajax with jsp/servlets
Problem with getRequestDispatcher()'s forward. Any alternatives?