aspose file tools*
The moose likes Struts and the fly likes redirect within a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "redirect within a servlet" Watch "redirect within a servlet" New topic
Author

redirect within a servlet

Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

Depends on the intended purpose and the rest of the surrounding code.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Jul 14, 2010
Posts: 754

Is there any return after that?


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 14, 2010
Posts: 754

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

Joined: Jan 10, 2002
Posts: 61761
    
  67

What happened when you tried it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: May 29, 2009
Posts: 122
@herbet: the only thing after wrting to the response is "return null;"
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is it setting a response code?

Again: without all the information we're just guessing.
Mark Wa
Ranch Hand

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: May 29, 2009
Posts: 122
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

Joined: Jul 14, 2010
Posts: 754

@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

Joined: Sep 29, 2008
Posts: 12617

@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

Joined: May 29, 2009
Posts: 122
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

Joined: Sep 29, 2008
Posts: 12617

Ah, that makes sense. It's always the details :)
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

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

Joined: May 29, 2009
Posts: 122
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.
 
Consider Paul's rocket mass heater.
 
subject: redirect within a servlet