background image

Comply with XML syntax

<< Creating a JSP Document | Declaring Tag Libraries >>
<< Creating a JSP Document | Declaring Tag Libraries >>

Comply with XML syntax

<form method=
"get">
<input type=
"text" name="username" size="25">
<p></p>
<input type=
"submit" value="Submit">
<input type=
"reset" value="Reset">
</form>
<jsp:useBean id=
"userNameBean" class="hello.UserNameBean"
scope=
"request"/>
<jsp:setProperty name=
"userNameBean" property="name"
value=
"${param.username}" />
<c:if test=
"${fn:length(userNameBean.name) > 0}" >
<%@include file=
"response.jsp" %>
</c:if>
</body>
</html>
Here is the same page in XML syntax:
<html
xmlns:c=
"http://java.sun.com/jsp/jstl/core"
xmlns:fn=
"http://java.sun.com/jsp/jstl/functions" >
<head><title>Hello</title></head>
<body bgcolor=
"white" />
<img src=
"duke.waving.gif" />
<h2>My name is Duke. What is yours?</h2>
<form method=
"get">
<input type=
"text" name="username" size="25" />
<p></p>
<input type=
"submit" value="Submit" />
<input type=
"reset" value="Reset" />
</form>
<jsp:useBean id=
"userNameBean" class="hello.UserNameBean"
scope=
"request"/>
<jsp:setProperty name=
"userNameBean" property="name"
value=
"${param.username}" />
<c:if test=
"${fn:length(userNameBean.name) gt 0}" >
<jsp:directive.include=
"response.jsp" />
</c:if>
</body>
</html>
As you can see, a number of constructs that are legal in standard syntax have been changed to
comply with XML syntax:
The taglib directives have been removed. Tag libraries are now declared using XML
namespaces, as shown in the html element.
The img and input tags did not have matching end tags and have been made
XML-compliant by the addition of a / to the start tag.
Creating a JSP Document
Chapter 6 · JavaServer Pages Documents
189