File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes Two HttpServletResponse Responses? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Two HttpServletResponse Responses?" Watch "Two HttpServletResponse Responses?" New topic
Author

Two HttpServletResponse Responses?

Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
How do I send two HttpServletResponse responses? I'm writing an app where I save a file to the user's PC and then redirect them to another page. I can save the file or redirect, but not do both. Here's my code:



If I leave it as-is, it will redirect to google without saving the file. If I comment out the redirect line, the file saves as it should.

Is there some way to make both work?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

You can only send one response.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
I kinda figured as much. Thanks for the confirmation.
Any easy ways around this? Or will it just be a "fun" little problem solving mission for me?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

It's not clear exactly what you are trying to accomplish by redirecting to google. If you were redirecting to something within your own app, that'd be different.
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
Sorry, I should have mentioned the google URL was just a filler. The actual app would redirect to another page within the site.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Try not to do that. Using "filler" in this case, creates a completely different environment for the question.

Generally, things like this are accomplished by redirecting to the next page first, and having JavaScript on that page that initiates the request that performs the attachment download.
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
Unfortunately, I'm unable to use JavaScript. The site this will be hosted on has a policy against using JavaScript (which has made the project more difficult than it should be... it's a longer story, but in the end I was told no JavaScript, so I went with that.)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Well, you certainly aren't going to be able to do that without some Javascript somewhere. So I guess your project sponsors are just out of luck there.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Ah yes, denying carpenters their saws.
Charles Swanson
Greenhorn

Joined: Nov 24, 2009
Posts: 9
Bear Bibeault wrote:Ah yes, denying carpenters their saws.


Haha, exactly. It's actually been a semi-entertaining challenge to build this thing without any JavaScript. It's certainly created some large and ugly code though...
Thanks for the help guys... at least I won't waste too much time finding a non-existent answer.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Two HttpServletResponse Responses?