File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Appending query strings to a URL

 
mike canmore
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Wallwork
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the ? included in your querystring? If not, try this:

hth,
-Pat
 
Pat Wallwork
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic