Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two HttpServletResponse Responses?

 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can only send one response.
 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21321
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65116
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes, denying carpenters their saws.
 
Charles Swanson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic