Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

redirect within a servlet

 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come across the following bit of code:



I dont understand, surely that will just write to the response the string containing the url, and not actually redirect the browser.

wouldn't be better?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the intended purpose and the rest of the surrounding code.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its intended to redirect to the url contained within the string. Nothing else is being done with the response object. I dont understand how that could work though
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Wa wrote:Its intended to redirect to the url contained within the string. Nothing else is being done with the response object. I dont understand how that could work though

Again, it depends on what else is done with it, the surrounding HTML, etc.

@Hebert: Huh?
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:
Mark Wa wrote:Its intended to redirect to the url contained within the string. Nothing else is being done with the response object. I dont understand how that could work though

Again, it depends on what else is done with it, the surrounding HTML, etc.

@Hebert: Huh?


Trying to be sure that he is doing nothing more with the attribute. I don't know with method he is inside or what is he using.
Just to check the ending of the code! [=
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It displays the url in the browser (ff) display pane. Yet when I switch it to response.sendRedirect() it works. but that is only on my local server. My colleague is adamant it works on the production server. Is there anyway this could work in some browsers? Perhaps IE is trying to be clever and realises as there's a response of only a URL, go there?
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@herbet: the only thing after wrting to the response is "return null;"
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it setting a response code?

Again: without all the information we're just guessing.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. Its a very complicated class, but very little is happening when i step through in debug. I was just trying to simplify it.

without any unneccesary code it looks like this:




obviously there is more to it than that, but thats all im concerned with. Also the code is not my own so I can't just go posting it on the internet.

Help appreciated.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not a servlet. In any case, since the action is returning null, I would expect nothing more than the URL string to show up in the response. It's trivial to test why that isn't happening on the prod machine (if it really isn't) by making the request through a logging proxy and seeing what, precisely, is being sent, and what's coming back.

But since it's Struts, there could be something in a custom request processor as well: this is why details are *important*.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply David.

Its not possible to test on the production server as the part of the app here is post-payment. However locally it's possible to spoof the payment. I will try to get it tested in firebug/fiddler. There is no custom request processor.

That is what I expected too. I just wanted to confirm that this was a strange and maybe not the best way of forwarding. I also dont understand how it could be working unless the browser is interpreting as a redirect, to which it is not.

I'll let you know the outcome.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@MarkWa Since you can run it in a test place, why don't you just comment the code and debug it? you might see what it is doing.!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Hebert: what the code is doing is clear. What is not clear is how it's working once the response is on the wire.
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like the request was not coming from the user's browser, but from a 3rd party server. Solved. The third party server is recieving the response and re-directing the users browser.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, that makes sense. It's always the details :)
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now just put a comment there so the next developer that sees don't have to burn some brain like you did!
 
Mark Wa
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert Coelho wrote:Now just put a comment there so the next developer that sees don't have to burn some brain like you did!


already one step ahead of you. //coments are awesome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic