File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Problem in request forwarding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in request forwarding" Watch "Problem in request forwarding" New topic

Problem in request forwarding

Hrishikesh Maha

Joined: Dec 16, 2001
Posts: 9
Iam using MVC architecture for an web application.
From an JSP file(test.jsp) I want to redirect to a bookmark in another JSP(test1.jsp) file.
Iam using the following code:
<a href="javascript://" click="javascript:return submitForm('redirect','/test/test1.jsp#12')">12</A>
The javascript submits the form to the controller servlet.
The controller servlet forwards the request to the page.
The problem in my case is the controller servlet does not forward the request to the JSP file and I see only a blank page.
I think the problem is coming due to the bookmark ("#") character.
Is there any way to solve the problem.
Thanks in advance,
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
What does the code in your javascript function submitForm look like?
Another thing to try is:
If all you're getting is a blank page there might be errors that are occuring that you aren't seeing. Check the localhost Tomcat log to see if thereare any errors gettng reported there. You can also put in some logging astatements to see exactley how far in your code you get before you get the blank page.

Hrishikesh Maha

Joined: Dec 16, 2001
Posts: 9
In the javascript function Iam just submitting the form.

I tried to put debug statements in the the servlet. But the code executes till the line where I forward the request to the URL which has bookmark (#).
After that Iam seeing a blank page.
But if I remove the # character from the URL then the request gets forwarded properly to the page.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
I seem to recall hearing that certain browsers have this problem, so it may not be your code at all.
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Cant you just strip the "#12" part of the url in the controller servlet?
So before creating the RequestDispatcher you only have "/test/test1.jsp" ?
Hrishikesh Maha

Joined: Dec 16, 2001
Posts: 9
Hi Axel,
I want to forwarded to the page with the bookmark so that when the page loads it directly goes to the book mark.
What you have suggested no doubt works without the bookmark character but my application requires it to forward with a bookmark
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Here is an ugly little hack I coded up, which seems to work in IE5.5 under Tomcat 4.0.1

You would need to change your requests from 'mypage.jsp#2' to 'mypage.jsp?a=2', and then use javascript to move the page...

Note the line:
window.location = "Test.jsp?a=<%= anchor %>#<%= anchor %>";

This is the ugly little hack part.

You will request:
And the browser bar will display:

Take out the "?a=<%= anchor %>" in the window.location line above, and uncomment the System.out.println from the JSP code to convince yourself why we need this.
Hrishikesh Maha

Joined: Dec 16, 2001
Posts: 9
Hi Mike,
Thanks....this seems to work.
I agree. Here's the link:
subject: Problem in request forwarding
It's not a secret anymore!