Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Http response containing XML document

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP response can contain whatever you like, it is not limited to HTML.
 
Sheriff
Posts: 67651
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic