• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with tag files

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You have not mentioned what is problem ?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Doesn't appear to be anything wrong with this code example.
Ran successfully in Tomcat 7.

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic