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

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Using JSP in pure XML generating conforming XHTML 
 

This JSP example describes how JSP tags for XML can be used in XML generation conforming XHTML.

 

Using JSP in pure XML  generating conforming XHTML

                          

Example program to demonstrate using JSP in pure XML generating conforming XHTML

This JSP example describes how JSP tags for XML can be used in XML generation conforming  XHTML. XHTML conformation is done by including the following code:

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>

Some of the important tags used in JSP files in their XML format is given as below:

  • <jsp:root>
  • <jsp:directive.page>
  • <jsp:declaration>
  • <jsp:scriptlet>
  • <jsp:expression>

<jsp:root> 

<jsp:root> tag provides standard JSP elements and namespace attributes of tag libraries.

XML Syntax for <jsp:root> tag

<jsp:root
   xmlns:jsp="http://java.sun.com/JSP/Page"
   [ xmlns:taglibPrefix="URI" ]+ version="1.2 | 2.0">
      JSP Page
</jsp:root>

This <jsp:root> can be used in JSP page as:

<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"   version="1.2">
...................
JSP page content
.......................
..................

</jsp:root>

JSP page in pure XML syntax have <jsp:root> as its root element, but it is not required. "version" attributes is mandatory.

<jsp:directive.page> 

It defines attributes to be applied for whole JSP page and to only static included files but not for dynamic file inclusion.

XML Syntax for <jsp:directive.page>(Page directive)

<jsp:directive.page listofPageAttributes />

In this example we are using two more tags <jsp:scriptlet> and <jsp:expression> to show content on a JSP page. Since in XHTML format JSP's sciptlet(<% code %>), expression(<%= expression %>), declaration(<%! declarationCode %>) do not work so their XML form is required.

Full code for XML-XHTML.JSP page is as follows:

XML-XHTML.jsp

<?xml version="1.0"?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2">
<jsp:directive.page contentType="text/html"/>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
&gt;
  <html>
  <head>
      <title>JSP in pure XML- XHTML</title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
     </head>
<body bgcolor="#ffffcc">
  <h1>XML-XHTML example</h1>
    <b><font color="red" size="5">
     <jsp:declaration> String fname="amit";</jsp:declaration>
     <jsp:declaration> String midname="kumar";</jsp:declaration>
     <jsp:declaration> String lname="raghuwanshi";</jsp:declaration>
     <jsp:declaration> int age=21;</jsp:declaration>
   <table border="1">
<tr>
    <td>First Name</td><td><jsp:expression> fname</jsp:expression></td>
</tr>
<tr>
    <td>Mid Name</td><td><jsp:expression> midname</jsp:expression></td>
</tr>
<tr>
    <td>Last Name</td><td><jsp:expression> lname</jsp:expression></td>
</tr>
<tr>
   <td>Age</td><td><jsp:expression> age</jsp:expression></td>
</tr>
    </table>
   </font></b>
   </body>
</html>
</jsp:root>

Output:

When we run tomcat server and execute this JSP page then output will be like as follows:

Download Source Code

                          

» View all related tutorials
Related Tags: c exception error jsp io count page using invoke js handle if to ci counter e directive can pe ce

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.