Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
JSP Write XML 
 

JSP technology is basically used for building HTML pages with dynamic content but you can use it to generate dynamic content in other formats as well, including XML.

 

JSP Write XML

                          

In this section you will study how to generate dynamic XML using JSP.

JSP technology is basically used for building HTML pages with dynamic content but you can use it to generate dynamic content in other formats as well, including XML. 

Understand with Example

The Tutorial illustrate an elaborate example on JSP Write XML. To understand the example we make use of java bean that include the string type variables. The java bean can make use of these variables by using setter ( ) and getter ( ) method. The setter ( ) and getter ( ) method are used to define the property of class variable.

set xxx( ) : The set xxx ( ) is used to set the values in variable.

get xxx( ) : The get xxx ( ) is used to access the values from the set xxx ( ) method.

You can see in the given example that we have used xml document in a jsp page and therefore we need to  indicate the JSP page compiler by using a JSP page directive tag to set the content type 'text/xml'. The page compiler will use the attributes of the <jsp:useBean> tag to build the Java code to instantiate the bean and populate it with data from the request. The scriplets <% out.print(xml.getId()); %>insert the results into the XML document from the Bean.

Here is the code of GenerateXml.java

package form;
public class GenerateXml{
  private String id = "1";
  private String name = "AAAA";
  private String address="Delhi"
  private String contactNo="9999999999"
  public void setId(String id) {
        this.id = id;
    }
    public String getId() {
        return this.id;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return this.name;
    }
  public void setAddress(String address) {
        this.address = address;
    }
    public String getAddress() {
        return this.address;
    }
  public void setContactNo(String contactNo) {
        this.contactNo = contactNo;
    }
    public String getContactNo() {
        return this.contactNo;
    }
}

Here is the code of xml.jsp

<?xml version="1.0" encoding="ISO-8859-1"?>
<%@ page contentType="text/xml;charset=ISO-8859-1" %>
<jsp:useBean id="xml" class="form.GenerateXml"/>
<Company>
<Employee>
<Employee_Id><% out.print(xml.getId()); %></Employee_Id>
<Employee_Name><% out.print(xml.getName()); %></Employee_Name>
<Employee_Address><% out.print(xml.getAddress()); %></Employee_Address> 
<ContactNo><% out.print(xml.getContactNo()); %></ContactNo>
</Employee>
</Company>

Output will be displayed as:

Download Source Code:

 

                          

» View all related tutorials
Related Tags: java c exception class control io multiple find ip exec lock state int block exe row with matching match statement

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.