File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes problem with tag files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "problem with tag files" Watch "problem with tag files" New topic
Author

problem with tag files

maheedar sand
Greenhorn

Joined: Feb 26, 2008
Posts: 23
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

Joined: Oct 11, 2011
Posts: 98
Hi,
You have not mentioned what is problem ?
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Doesn't appear to be anything wrong with this code example.
Ran successfully in Tomcat 7.

Arvind Rao
Greenhorn

Joined: Jun 24, 2011
Posts: 8
Hi,

What exactly seems to be your problem?.

Arvind.
maheedar sand
Greenhorn

Joined: Feb 26, 2008
Posts: 23
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
Greenhorn

Joined: Feb 26, 2008
Posts: 23
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.
 
Consider Paul's rocket mass heater.
 
subject: problem with tag files