Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding # to jsp:param 1

Status
Not open for further replies.

joelmac

Programmer
Jun 4, 2002
92
CA
Hey there,

I'm forwarding from one jsp page to another using:

<jsp:forward page=&quot;PicView.jsp&quot;>
<jsp:param name=&quot;photoID&quot; value=&quot;<%=strPid%>&quot;/>
<jsp:param name=&quot;SGID&quot; value=&quot;<%=strSGID%>&quot;/>
</jsp:forward>

Which should goto &quot;PicView.jsp?photoID=strPid&SGID=strSGID&quot;, right?? I want to go one step farther and goto here: &quot;PicView.jsp?photoID=strPid&SGID=strSGID#place&quot; ________________________
JoelMac
 
Never tried that but if it works it has to be

PicView.jsp#place?photoID=strPid&SGID=strSGID
 
No, &quot;PicView.jsp?photoID=strPid&SGID=strSGID#place&quot; is what it has to be, but I need to use it in the <jsp:forward><jsp:param/></jsp:forward> tags. ________________________
JoelMac
 
Guess I didn't follow your post. I thought #place was an anchor on the page you are forwarding to that you wanted the browser to go to when the page loaded.

I still don't know what you mean by it.

-pete
 
Yes that's right #place is an anchor. I want to forward to that page and then jump down to the &quot;place&quot; anchor. If I just type &quot;PicView.jsp?photoID=123&SGID=456#place&quot; in the address bar it works fine.

It starts at a form which is submited to a page that does some processing. That page has to be able to forward to a third page, which it does fine. It would be nice to have it move down the page a little once it has forwarded though.

does this make sence?? ________________________
JoelMac
 
Ok now I have a grasp on it... well maybe :)

The browser is what has to scroll to the anchor so you might consider mixing some client code into your design. Do something in an onload() handler like:

So if the forwarding .jsp page has to tell the picView.jsp page what the name of the anchor is just pass the name in a parameter like the other values then in the code in picView.jsp do something like

<body
onload=&quot;document.location =
'#<%=request.getParameter(&quot;whatever&quot;)%>';&quot;>

...
</body>

Hope this helps
-pete
 
yes, I guess that would do the job, but there has to be a way to do it without a client-side script. There must be some property in the <jsp:forward> tag that can do that.

Is there someplace with good documentation on jsp tags? ________________________
JoelMac
 
Well normally you can just type &quot;PicView.jsp?photoID=546&SGID=6546#place&quot; in the address bar and goto that page, use those parameters, and jump down to the place anchor on the page, right?? No Client-side script, or any script for that matter.

So why can't I forward to the page and do the same thing?? ________________________
JoelMac
 
>> So why can't I forward to the page and do the same
>> thing??

>> The browser is what has to scroll to the anchor


You are forwarding to a server page/code not giving the browser a location to scroll to. Then the server page produces the HTML that is streamed to the browser which it just renders.

-pete
 
Palbano, Have you ever used the # in the url before? I don't think you understand what I'm talking about.

If you have a long page you can put in anchors around things like headers like this:

...
<a name=&quot;place&quot;>Header</a>
...


If the file name of the page is &quot;thing.html&quot; then you can type &quot;thing.html#place&quot; in the address bar on the browser and it'll goto that page and scroll down to the &quot;place&quot; anchor. Without scripts.

I want to append it to the <jsp:forward> tag.

Does that make sence to anyone?? ________________________
JoelMac
 
>> on the browser and it'll goto that page and scroll down
>> to the &quot;place&quot; anchor.

Yeah Joel, that's exactly what I said:

>> The browser is what has to scroll to the anchor


-pete
 
yes, but normally you wouldn't need to write a script to do it. It's automatic. ________________________
JoelMac
 
Correct, if your link is in the browser

<a href=&quot;foo.com/home.jsp#place2&quot;>Go</a>

Then the browser has the url including the anchor. So it's HTTP request looks like:

GET /home.jsp HTTP:1.1


It keeps the anchor location in memory #place2 and does the scrolling after it renders the html that the server sends it.

In your case you are sending the anchor to the .jsp page for processing. You are running code on the server which the browser knows nothing about.

-pete
 
I'm still not totally convinced that you know what I'm talking about.

Anyway I found the answer that I was looking for:

<%
response.sendRedirect(&quot;PicView.jsp?photoID=8987&SGID=5642#photo&quot;);
%> ________________________
JoelMac
 
>> I'm still not totally convinced that you know what I'm
>> talking about.

That's ok... as long as I'm convinced that I know what I'm talking about LOL

Code:
response.sendRedirect(&quot;PicView.jsp?photoID=8987&SGID=5642#photo&quot;);

Now let me try to convince you that you don't want to do that. The technique you are using there is going to take an extra round trip between the browser/server so is therefore much less efficient than a simple client script that tells the browser to scroll to the anchor.
Code:
<script language=&quot;javascript&quot; for=&quot;onload&quot;>
document.location = &quot;#photo&quot;;
</script>

-pete

 
Why is another round trip needed?

It turns out that your way might be better anyways. My way seems to be buggy in IE, works a little better in Netscape, but not well enough. My biggest problem with your way was just: Why use cleint side scripts when they're not needed, but it seems that's the best option after all.

Thanks ________________________
JoelMac
 
>> Why is another round trip needed?

Well when you use the response.Redirect method your code is running on the web server. So the steps look like this:

1) Server code sends HTTP Redirect response back to the browser with the target URL

2) Browser reads, parses response to obtain the URL

3) Browser makes a new request for the URL

4) Server processes new request and responds with the resource.

Hope this helps
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top