805 OCPJP 6 Questions 788 SCJP 5 questions 650 OCPJWCD 5 questions 600 OCAJP 7 questions 610 OCPJP 7 questions 510 Upgrade to OCPJP 7 questions 900 Java J2EE Qns

Tutorials

SCWCD : JSP Document (XML-based document) that uses the correct syntax

Write a JSP Document (XML-based document) that uses the correct syntax.

JSP syntax comment:


<%-- comment --%>

					
has no XML syntax analog.

JSP syntax page directive:


<%@ page ... %>

					

XML syntax page directive:


<jsp:directive.page ... />

					

JSP syntax taglib directive:


<%@ taglib ... %>

					
has no XML syntax analog.

jsp:root element is annotated with namespace information:


<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
	xmlns:eg="http://java.apache.org/tomcat/examples-taglib"
	xmlns:test="urn:jsptld:/tomcat/taglib"
	xmlns:temp="urn:jsptld:/WEB-INF/tlds/my.tld"
	version="2.0">

	...

</jsp:root>

					

A taglib directive of the form


<%@ taglib uri="uriValue" prefix="prefix" %>

					
is translated into an xmlns:prefix attribute on the root of the JSP document, with a value that depends on uriValue.
  • If uriValue is a RELATIVE path, then the value used is urn:jsptld:uriValue.

  • If uriValue is a ABSOLUTE path, then uriValue is used directly.

A taglib directive of the form:

<%@ taglib tagdir="tagDirValue" prefix="prefix" %>

					
is translated into an xmlns:prefix attribute on the root of the JSP document, with a value of the form urn:jsptagdir:tagDirValue.

JSP syntax include directive:


<%@ include file="relativeURL" %>

					

XML syntax include directive:


<jsp:directive.include file="relativeURL" />

					
A file on the local system to be included when the JSP page is translated into a servlet. The URL must be a relative one.

JSP syntax declaration:


<%! ... %>

					

XML syntax declaration:


<jsp:declaration> ... </jsp:declaration>

					

Declarations are translated into a jsp:declaration element. For example:


<%! 
	public String someFunc(int i) {
		if (i<3) return("...");
	} 
%>

					
is translated into the following:

<jsp:declaration> 
	<![CDATA[
		public String someFunc(int i) {
			if (i<3) return("...");
		} 
	]]>
</jsp:declaration>

					
Alternatively, we could use an &lt; and instead say:

<jsp:declaration> 
	public String someFunc(int i) { 
		if (i&lt;3) return("..."); 
	} 
</jsp:declaration>

					

JSP syntax scriptlet:


<% ... %>

					

XML syntax scriptlet:


<jsp:scriptlet> ... </jsp:scriptlet>

					

JSP syntax expression:


<%= ... %>

					

XML syntax expression:


<jsp:expression> ... </jsp:expression>

					

JSP syntax template text:


some template text

					

XML syntax template text:


<jsp:text>
	some template text
</jsp:text>

					

A JSP document syntax:


<html>
	<title>positiveTagLib</title>
	<body>
		<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" 
			prefix="eg" %>
		<%@ taglib uri="/tomcat/taglib" prefix="test" %>
		<%@ taglib uri="WEB-INF/tlds/my.tld" prefix="temp" %>
		<eg:test toBrowser="true" att1="Working">
		Positive Test taglib directive </eg:test>
	</body>
</html>

					

A XML document syntax:


<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
	xmlns:eg="http://java.apache.org/tomcat/examples-taglib"
	xmlns:test="urn:jsptld:/tomcat/taglib"
	xmlns:temp="urn:jsptld:/WEB-INF/tlds/my.tld"
	version="2.0">

	<jsp:text><![CDATA[
<html>
	<title>positiveTagLib</title>
	<body>
	]]></jsp:text>

	<eg:test toBrowser="true" att1="Working">
		<jsp:text>Positive test taglib directive</jsp:text>
	</eg:test>

	<jsp:text><![CDATA[
	</body>
</html>
	]]></jsp:text>

</jsp:root>

					

scjp 1.5 | scjp 1.6 | scwcd 1.5
Java Certifications
www.javacertifications.net