Chapter 10 Custom Tag Development

(*) Tag File
Store the tag files in /WEB-INF/tags folder.
The name of the tag file will become the tag name. (Header.tag ==> Header will be the name of the tag in JSP)

JSP usage

< %@taglib prefix="mytags" tagdir="/WEB-INF/tags" %>
  • note that the tagdir attribute used instead of uri attribute
  • tagdir value is the folder where the tag files are located
<mytags :Header subtitle="Welcome" />
  • Header was the name of the file. (Header.tag)

Header.tag

<em><strong>${subtitle}</strong></em>

Read the rest of this entry »

Chapter9 using JSTL

JSTL is not part of JSP 2.0 spec. (jstl.jar & standard.jar copy needed)

(*) <c:out>

<c :out value='${pageContent.currentTip}' escapeXml="true" default="No tip" />
  • escapeXML: when true, escapes HTML special characters (<,>,&,’,”) and default value is true.
  • default: attribute is to show default value when the value attribute data is null. Or default value can be defined in the body.

(*) <c:forEach>

<c :forEach var="movie" items="${movieList}" varStatus="info">
	<tr><td>${info.count}</td><td>${movie}</td></tr>
</c>
  • Items: array, collection, map, comma delimited string
  • varStatus: extra object that you can get count information.
  • <c:forEach> can be nested.

(*) <c:if>

<c :if test="${userType eq 'member'}" >
	<jsp :include page="input.jsp" />
</c>

Read the rest of this entry »

Chapter 8 scriptless JSP

Accessing the JavaBean object using Standard Action (<jsp: >)

<jsp :useBean id="person" class="foo.Person" scope="request" />
<jsp :getProperty name="person" property="name" />

*jsp:useBean action tries to find the attribute name in the defined scope when there is any attribute match id name, it creates a new object using the class info defined in the class attribute.

*The useBean’s id attribute and the getProperty’s name should match.
getProperty’s property attribute is for getter and setter.

*setProperty is to set the member of the java Bean object.
<jsp:setProperty name="person" property="name" value="Fred" />

* if setProperty tag is used within useBean tag body, then it is used only conditionally when the bean object is created

<jsp :useBean id="person" class="foo.Person" scope="page" >
	<jsp :setProperty name="person" property="name" value="Fred" />
</jsp>

Read the rest of this entry »