aspose file tools*
The moose likes Servlets and the fly likes Appending query strings to a URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Appending query strings to a URL" Watch "Appending query strings to a URL" New topic
Author

Appending query strings to a URL

mike canmore
Greenhorn

Joined: Jan 14, 2003
Posts: 3
Can anyone help?
I'm trying to append a querystring to an existing url (eg http://abc.com/servlet/testservlet) and to send that same url back to the client but with the querystring added.
If I use response.sendredirect(existingUrl + querystring) to achieve this, the browser just tries to execute the new url and returns to my code, resulting in an endless loop - is there any way around this?
[ January 14, 2003: Message edited by: mike canmore ]
Tom McComb
Ranch Hand

Joined: Jun 07, 2001
Posts: 30
Mike,
If you are using this:

then you need to check to see if the new stuff is there before you send the redirect, like this:

I hope this makes sense.


Tom McComb
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Is the ? included in your querystring? If not, try this:

hth,
-Pat
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
I reread your question and understand what your trying to do now. Tom's suggestion sounds good. If your not checking for a query string then your servlet will keep redirecting the client resulting in that endless loop.
Another idea might be to use the session.

-Pat
mike canmore
Greenhorn

Joined: Jan 14, 2003
Posts: 3
Thanks for your answers people.
The problem is that the code I'm writing is to be used as an application flow control mechanism "wrapped" around an an existing servlet app. To achieve this, an encrypted token is passed around the application in a querystring and is checked for validity by the filter.
If the token is invalid, then the filter directs the client to an error page, but if it's valid, the original servlet is executed, performs it's processing and uses a forward to return to the client. I was planning to use the filter to intercept the response, update the token, and then do a redirect to the original url + new token value. The problem is that even with the suggested code above, the app will still loop after the redirect as the querystring will always be the same, but just with a different value.
mike canmore
Greenhorn

Joined: Jan 14, 2003
Posts: 3
BTW I realise that this is not a great solution, but we cannot use the session at all.
I think that cookies are probably the answer, although I was trying to avoid using them if at all possible.
 
 
subject: Appending query strings to a URL