Generating XML Document Using JSP

JSP, one of the important and powerful technologies for building web application and can be explained as a combination of java (inside JSP tags) and HTML tags in such a way which leads to the creation of dynamic HTML pages.

In addition to the creation of dynamic HTML content, JSP can also be used for generating dynamic XML document. This is done by sending XML tags in the form of strings as a output of JSP page. You will understand better on how to accomplish this with the help of following example:


_______________________________________________

<%@ page contentType=”text/xml” %>
<?xml version=”1.0”?>
<studentdata>
<name>
Robert
</name>
<qualification>
B.Tech
</qualification>
</studentdata>

As you know the output of a JSP page is the whole content leaving JSP directives and other constructs. This is the reason you have not used any output method for passing the XML tags. It is worth to note here that JSP directives are a type of JSP tags used to perform a specific task in a program and begin with <@. Some commonly used directives are import include etc.

Looking into the above example you can see that here its been used as the JSP directive “page” and its attribute “contentType”. Its value is equated to the string “text/xml” in order to guide the browser (which is going to show the output of JSP) about the type of content.

Generally the default value of contentType is text/html but here as we are generating an XML document so it is mandatory to set the contentType as “text/xml”.
Let us call the above jsp as example.jsp. Now when you run the example.jsp on server ( or JSP container like Tomcat) we will get the following XML as output:

<?xml version="1.0" ?>
- <studentdata>
<name>Robert</name>
<qualification>B.Tech</qualification>
</studentdata>

So you can easily create an XML using JSP. This method can also be used for creating other markup documents by using JSP.



_______________________________________________

FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

_______________________________________



| All About Different Types of XML Editors | Generating XML Document Using JSP | How to Retrieve an Email Message Using Java Mail API | How to Send an Email Message Using Java Mail API | Transforming XML Data with XSLT | Understanding Basic Components of a JMS Program | Understanding Basic Technology of ebXML | Understanding Deployment Descriptor in Reference with Servlets | Understanding eXtensible Access Control Markup Language (XACML) | Understanding the Design Goals of XML | Understanding XML Common Biometric Format |

FREE Subscription

Stay Current With the Latest Technology Developments Realted to XML. Signup for Our Newsletter and Receive New Articles Through Email.

Name:

Email:

Note : We never rent, trade, or sell our email lists to anyone. We assure that your privacy is respected and protected.

 

 

Add to My Yahoo!

Visit XML Training Material Guide Homepage

 

 

 

Copyright - © 2004 - 2017 - All Rights Reserved.