• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with tag files

 
maheedar sand
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Miku Ranjan
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You have not mentioned what is problem ?
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't appear to be anything wrong with this code example.
Ran successfully in Tomcat 7.

 
Arvind Rao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What exactly seems to be your problem?.

Arvind.
 
maheedar sand
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the problem but I tried using tomcat 5.0.8. It is unable to find the tadir location of "/WEB-INF/tags". I tried using tomcat 7. It is working fine. Thanks for the help.
 
maheedar sand
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry for the bit of confusion involved with me. Actually the text place in tags [cde]/[/cde] have to replaced with <pre>/</pre> but it is not in tomcat 5 so I tried using tomcat 7. It is working fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic