Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Http response containing XML document

 
P Jain
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to this group, I want to know that how do I send a response from server which contain XML document or a specific XML element(that contains other elements aslo).

P Jain
 
Khan Malamir
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP response can contain whatever you like, it is not limited to HTML.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, since this is the servlets forum, I'd say that the servlet output can contain any data that the author would like.

If you want the response to be treated as XML on the client, be sure to set the content type header to "text/xml".
 
Sravan Kumar
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

JSP RESPONSE:
<%@ page contentType="text/xml;charset=ISO-8859-1"%>
// Write the XML in JSP file.

SERVLET RESPONSE:
response.setContentType("text/xml;charset=ISO-8859-1");
// Print the XML in the response object.

NOTE:
1. Both the above approaches display the XML in the browser.
2. You can even generate dynamic content (say, bring data from backend and display in XML), the way you do normally.
3. If you want the XML to download as a document, you would have to send it as a response attachment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic