This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes Redirecting servlet response between windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Redirecting servlet response between windows" Watch "Redirecting servlet response between windows" New topic
Author

Redirecting servlet response between windows

Ulvi Cetin
Ranch Hand

Joined: Mar 03, 2003
Posts: 39
I have 2 browser windows open (say A and B). On one of the windows (say on A), when I click on the submit button, it calls a servlet (which does some stuff). When the servlet finishes, I want to send the resonse to the other browser window (window B). I am using response.sendRedirect(), but this is sending it back to the original window (A), as expected. Is there a way to send the response to the other window?
Thx.
Ulvi.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
The thing is - a response is always sent to the browser a request came from.
Your browser B might be running some sort of JavaScript loop checking for the availability of the newly computed page.
It would be easiest if window B was opened from window A so they would share the same sessionID cookie.
Bill
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

As William pointed out, once the request is sent to a specific window, that is where the response will be sent.
If you want the response to appear in the 2nd window, you will need to submit the request to it and not to the first window.
If the request is triggered via a form submission, or the result of clicking a link, you can control which window the request is submitted to with the target attribute in the form or anchor tag.
If you need more control than that, you can create the window via window.open() and then control any Javascript in the page loaded into that window, or even submit the request directly to that window.
hth,
bear
[ July 22, 2003: Message edited by: Bear Bibeault ]
[ July 22, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951
    
  19

Or, to put it another way, HTTP can't send unsolicited information, only info in response to a request.
And the response always goes back to the same place it was requested from.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Don't get me started about those stupid light bulbs.
 
subject: Redirecting servlet response between windows
 
Similar Threads
Display String in new window
how does the servlet knows that the client has closed the browser
response.sendRedirect not working when Parent window is closed - Help
Tracking browser events in applet
Content-Disposition http header