Wednesday, April 6, 2011

Chapter 33: JSP Tags & XML

JSP Tags can be used in two ways. One is the regular JSP Tag construct we saw in the previous chapters and the other is the XML Equivalent. In this chapter, we are going to find out the XML Equivalents of the tags that can be used both ways…

So, lets get started!!!

JSP Tags as XML

JSP enables you to use two forms of certain tag types. Below is a table that tells you all you need to know about these tags.

JSP Tag Category Regular Syntax XML Equivalent Syntax
Expression <%=expression%> < jsp : expression >

expression

< / jsp : expression>

Scriptlet <% yourCode %> < jsp : scriptlet >

yourCode

< / jsp : scriptlet >

Declaration <%! yourCode %> < jsp : declaration >

yourCode

< / jsp : declaration >

page Directive <%@ page att="val" %> < jsp : directive.page att="val"/>
include Directive <%@ include file="url" %> < jsp : directive.include file="url"/>
Actions N/A - XML Tags only < jsp : useBean>

< jsp : setProperty>

< jsp : getProperty>

< jsp : include>

< jsp : forward>

< jsp : plugin>

Tag Library <%@ taglib uri="URIForLibrary" prefix="tagPrefix" %> N/A - Regular Tags only. No XML Equivalent
Example:

Let's compare two code snippets that result in the same output. The first uses the regular JSP syntax:
<%@ page language="java" %>
<%=someVariable%>

The second snippet generates the same results as the previous snippet using the XML equivalent:

someVariable

There is no way that, these two pieces of code provide a different output. They provide the exact same output eventhough they use two totally different syntax.

After seeing the XML Equivalents of the JSP Tags, we are left with the Action Tags that we can use only in XML format. Let us wrap up this chapter, by taking a look at those tags as well…

JSP Tag Category Syntax Example
Bean < jsp : useBean > < jsp : useBean id="calc" scope="page" class="session.Calc" />
Bean property < jsp : setProperty> < jsp : setProperty name="amount" property="56.90" />
Bean property < jsp : getProperty > < jsp : getProperty name="calc" property="amount" />
Dispatch < jsp : forward > < jsp : forward page="welcome.html" >
Include < jsp : include> < jsp : include page="copyright.html" />
Plugin < jsp : plugin> < jsp : plugin type=applet code="Customer.class" codebase=" / html ">
< jsp : params >
< jsp : param name="debt" value="large" />
< / jsp : params>
< jsp : fallback>

Unable to load applet

< / jsp : fallback>
< / jsp : plugin>

Previous Chapter: Chapter 32 - Opening & Closing JSP Tags

Next Chapter: Chapter 34 - The Page Directive

No comments:

Post a Comment

© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.

ShareThis

Google+ Followers

Followers