I am practicing custom tag libraries in
JSP. Please, check up the web application placed as attachment.
when we execute "forum.jsp" under pages folder it is not showing up any text placed under the variable "message". I checked with the book examples. They are working fine. what's wrong with my code. I'm not able to catch up. Please, help me.
source code of web application:
"forum.jsp" - this will be under pages folder
=============================
<%@ page contentType="text/html" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="my" tagdir="/WEB-INF/tags" %>
<%-- create
test data --%>
<c:set var="message">
This is just a lot of text that the browser will format to fit the browser
window. Attempts to <blink> add HTML elements are dealt with by conversion
to character entities.
[cde]
This part I want the browser to leave alone, so that all my indentations are
left intact:
public class Foo {
public
String getBar() {
return bar;
}
}
[/cde]
And then some regular text again.
</c:set>
<html>
<head>
<title>Online Forum</title>
</head>
<body bgcolor="white">
<h1>Online Forum</h1>
Here's a formatted message:
<my:htmlFormat>
${message}
</my:htmlFormat>
</body>
</html>
"htmlFormat.tag" - tag file placed under "WEB-INF/tags" folder ( used for processing message in the above jsp page )
===============================================================================
<%@ tag body-content="scriptless"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- capture the body evaluation result in a variable --%>
<jsp:doBody var="bodyRes"></jsp:doBody>
<%-- convert special characters to character entities --%>
<c:set var="escapedBody" value="${fn:escapeXml(bodyRes)}"></c:set>
<%-- replace "[cde][/cde]" with "<pre></pre>" --%>
<c:set var="convBody" value="${fn:replace(escapedBody, '[cde]', '<pre>')}"></c:set>
<c:set var="convBody" value="${fn:replace(convBody, '[/cde]', '</pre>')}"></c:set>
<%-- output the result --%>
${convBody}
rest of the application code is normal deployment descriptor with welcome file, no
java class files.