This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Combine 2 content types in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "Combine 2 content types in a servlet" Watch "Combine 2 content types in a servlet" New topic

Combine 2 content types in a servlet

Pavlos Chatzidimitriou

Joined: Aug 18, 2008
Posts: 10
Hi all i start learning servlets now and i have a question about how can in one servlet send an html page and a file such as a photo in the response.I have this servlet :

It runs but i get only the html page without downloading the file.Now i wonder if i have to make a second servlet for the file but then how can i do this.Any suggestions?
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

You can't send two different content types over a single response. You will need two response, which means you will need two different requests (as responses can only be sent after a request was made).

The easiest way is probably to have the HTML page you send trigger the second response, either using javascript or an internal frame (iframe) to send a request to a second servlet that then initiates the download.

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Combine 2 content types in a servlet
It's not a secret anymore!