0

I have a getRequestDispatcher in my servlet that should redirect to an anchor url:

RequestDispatcher view = request.getRequestDispatcher("index.jsp#stuff");
view.forward(request, response);

And in my jsp page (called index.jsp), I have a modal with the id "stuff". Why is the servlet not redirecting it back to the modal??

Thanks!

kchow23
  • 111
  • 2
  • 2
  • 11
  • 1
    did you try to access the jsp directly in the browser to see if it works? ie: http://yourhost/index.jsp#stuff – fmodos Jun 12 '13 at 19:50
  • I guess that's the issue. It doesn't access directly. How can I make it so I can access it? – kchow23 Jun 12 '13 at 20:16

2 Answers2

1

That's not how that works. The RequestDispatcher is not a browser that can interpret HTML ids.

When you do

request.getRequestDispatcher("index.jsp#stuff");

you are telling your servlet container to find a resource at the path index.jsp#stuff. See the javadoc here. If that is not a valid resource path, then the method will return null.

None of this controls how your browser is going to center on some element.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
0

This works for me

response.sendRedirect("/index.jsp#stuff");  
shak
  • 641
  • 9
  • 13