Escaping HTML in a Custom Tag
Hello, all. I am sadly failing to find a library function to escape HTML in Java. I'm writing a tag that used to use JSTL as a custom tag and don't know exactly where to find the functionality the JSTL is using. Consider the old JSP:
<c:forEach items="${versions}" var="version">
<tr>
<td><c:out value="${version.version}"/></td>
<td><c:out value="${version.releaseDate}"/></td>
</tr>
</c:forEach>and the new custom tag class:
public class VersionTableTag implements Tag
private PageContext context;
private Tag parent;
public int doEndTag() throws JspException
return EVAL_PAGE;
public int doStartTag() throws JspException
JspWriter out = context.getOut();
List versions;
try
versions = (List)(context.getVariableResolver().resolveVariable("versions"));
} catch (ELException e)
versions = new ArrayList();
try
out.println("<table>");
out.println("<tr>");
out.println("<th>Version</th>");
out.println("<th>Release Date</th>");
out.println("</tr>");
for (Object o : versions)
VersionVO version = (VersionVO)o;
out.println("<tr>");
out.println("<td>");
out.println(version.getVersion()); // NOTE: not properly escaped
out.println("</td><td>");
out.println(version.getReleaseDate().toString()); // NOTE: not properly escaped
out.println("</td>");
out.println("</tr>");
out.println("</table>");
} catch (IOException e)
throw new JspException(e);
return SKIP_BODY;
}My questions are as follows:
*1.* Is it possible to define a tag using a JSP document rather than a Java class? All I'm really after is something similar to an include but I want to be able to provide attributes to it in the long run.
*2.* Is there some library function I can use to escape the HTML in the VO above?
1. Is it possible to define a tag using a JSP document rather than a Java class? All I'm really after is something similar to an include but I want to be able to provide attributes to it in the long run.Yes. It was introduced with JSP2.0: tag files.
Just like a JSP lets you write a servlet easily, a tag file lets your write a Custom tag class easily.
http://java.sun.com/javaee/5/docs/tutorial/doc/bnama.html
2. Is there some library function I can use to escape the HTML in the VO above?
There is one provided in the jakarta commons "lang" library.
http://commons.apache.org/lang/
They provide a class "StringEscapeUtils" which will do most of the common escaping that you require.
How hard is it to write something that replaces & < and > though?
Similar Messages
-
Include external html trough code in a custom tag
Hi,
I have a custom tag. The component class (say MyComponentUI) for my custom component extends UIComponentBase.
I want to include an external html page, which url is formed using the content of an attribute of my tag (for example, the "value" attribute), through the MyComponentUI code.
Can anyone give me some help ?
PietroThat's actually the same result as you get with a normal include - The method I suggested is a dynamic include similar to the <jsp:include> tag, not the <%@ include %> tag.
When you use a dynamic include, the included page is compiled and 'invoked' as serarately, and the result is what gets included, not the actual source. To get the behaviour you want would require an include directive (the <%@ include %> tag) which I don't think has an equivalence you can use inside a custom tag.
What you can do is pass attributes from the tag class like this:
pageContext.setAttribute(<name>, <object>, pageContext.REQUEST_SCOPE);
and then remove them after the include using pageContext.removeAttribute.
I'm not certain, but this implies that if you declare your variables with a <jsp:usebean> tag with request scope, instead of normal Java variable declarations, you should be able to use them in the page included by the custom tag.
*** in the jsp ***
<jsp:useBean id="myVar" scope="request" class="java.lang.String" />
<% myVar = "Something"; %>
// Now call the tag which uses the pageContext.include() mehtod.
*** end ***
*** in the include ***
<jsp:useBean id="myVar" scope="request" class="java.lang.String" />
<%= myVar + " something else" %>
*** end ***
Let me know if it works. -
Hi all,
I have af:inputText with:
<af:autoSuggestBehavior suggestedItems="#{myBean.partSuggestedItems}"/> .
I am constructing the " List<SelectItem>" normally. No problem.
I am using code like:
SelectItem selectItem = new SelectItem();
selectItem.setValue(eValue);
selectItem.setLabel(eLabel);
...How can I escape HTML tag to be treated as HTML tag instead of pure string?
How can I achieve this??
Please advice.Escape property can be defined on Output text only, not on input text.
I want to add style in the auto suggested list. So the values shown in Italic, or some color.
selectItem.setLabel(); expects a String.
So I want to fill my string with HTML tags.
I tried:
String italic = "<i>" + eLabel + "</i>";
selectItem.setLabel(italic);But obvious that did not work.
Can I escape HTML tags in a String value?? -
Escape HTML content without escaping tags
How can I escape HTML content without escaping the HTML tags?
Thanks for the info. The select statement worked for me when I ran it with the inputs below but when I tried to put the statement in my code it didn't work. Can you have a look and see what I may have done wrong?
Thanks
Karen
My code looks like this:
FUNCTION escape_varchar(p_text_in IN VARCHAR2, p_encode IN NUMBER)
RETURN VARCHAR2
IS
p_text_out VARCHAR2(32767);
BEGIN
p_text_out := DBMS_XMLGEN.CONVERT(utl_i18n.escape_reference(unistr(REPLACE(p_text_in,'\','\\')),'US7ASCII'),p_encode);
RETURN p_text_out;
END escape_varchar;
p_text_in =
<html>
<head>
</head>
<body>
Make sure the following characters are getting Displayed in EIS
~`!@#$%^&*()_-+={}|[]\:;"'<>?,./ ¢ £€¥©®™‰µ >• • … §¶ß‹›«»==–—¯ ?¤¦¨¡¿ˆ˜°-±÷/×¹²³¼½¾ ƒ??8v˜?=?¬n?´¸ªº
†‡ÀÁÂÃÄÅÆÇÈÉÊËÌÎÏÐÑÒÓÔÕÖØŒŠÙÚÝÜŸÞàáâãäåæçèéêëì í î ï ðñòóôõøœšùúûüýþÿ??G????T?????????S??F??Oaß?de?????
?µ???p??st?f??????????????
</body>
</html>
p_encode = 0
p_test_out =
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body&gt;
Make sure the following characters are getting Displayed in EIS
~`!@#$%^&amp;*()_-+={}|[]\:;&quot;&apos;&lt;&gt;?,./ &#xa2; #&#x20ac;Y&#xa9;&#xae;&#x2122;&#x2030;&#xb5; &gt;&#x2022; &#x2022; &#x2026; &#xa7;&#xb6;&#xdf;&#x2039;&#x203a;<>==&#x2013;&#x2014;&#xaf; ?&#xa4;|&#xa8;!&#xbf;&#x2c6;&#x2dc;&#xb0;-&#xb1;&#xf7;/&#xd7;&#xb9;&#xb2;&#xb3;&#xbc;&#xbd;&#xbe; &#x192;??8v&#x2dc;?=?&#xac;n?'&#xb8;&#xaa;&#xba;
&#x2020;&#x2021;AAA&#xc3;A&#xc5;&#xc6;CEEEEIII&#xd0;&#xd1;OOO&#xd5;O&#xd8;&#x152;SUUYU&#x178;&#xde;aaa&#xe3;a&#xe5;&#xe6;ceeeei i i i &#xf0;&#xf1;ooo&#xf5;&#xf8;&#x153;suuuuy&#xfe;y??G????T?????????S??F??Oa&#xdf;?de?????
?&#xb5;???p??st?f??????????????
&lt;/body&gt;
&lt;/html&gt; -
Hi,
We created a custom TLN.
I would like to produce href tags but I face the problem of escaping HTML characters :
<aa on_click="return EPCM.doNavigate('<%= currNavNode.getName()%>',0,'','null',1,'<%= *StringEscapeUtils.escapeHtml(*currNavNode2.getTitle(userLocale))%>','')" href="#"><%=currNavNode2.getTitle(userLocale)%></aa>
The problem is that the org.apache.commons.lang.StringEscapeUtils is not available (or I do not know how to make it available...).
How do you proceed for escaping :
- HTML
- URL
- Javascript
Thanks in advance for your help.
Best regards,
GuillaumeHi,
After many tries, I found out that simply quotes and double-quotes is enough for the Javascript EPCM.doNavigate to work (almost) properly.
Here is the code I use in the toplevelnavigation.jsp :
<% String titlePage = "";
String escTitlePage = "";
titlePage = currNavNode2.getTitle(userLocale);
escTitlePage = titlePage;
escTitlePage = escTitlePage.replaceAll("\'","\\\\\'");
escTitlePage = escTitlePage.replaceAll("\"","\\\\\"");
//escTitlePage = escTitlePage.replaceAll("\\&","\\&");
//escTitlePage = escTitlePage.replaceAll("\\&","\\%26");
%>
<a <%=level2Id%> oncclick="return EPCM.doNavigate('<%= currNavNode2.getName()%>',0,'','null',1,'<%= escTitlePage %>','')" href="#"><%= titlePage %></a>
The last problem I have is with '&'. Whatever escaping I try, I have a truncated string in the page title at position of the '&'...
Any idea ?
Thanks in advance.
Best regards,
Guillaume -
Why doesn't my custom tag work?
First, my backend database is MS Access. Nothing I can do about that, unfortunately.
I have defined three custom tags (no body, no attributes) to display report information from my project tracking/metrics Access database:
<prefix:showProjectInfo />
<prefix:showProjectTeam />
<prefix:showProjectHistory />
In my JSP, the first tag I use, <prefix:showProjectInfo />, works perfectly. However, <prefix:showProjectTeam /> gives no output.
First, here is the tld file that defines the tags (report.tld):
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>report</short-name>
<uri>/report</uri>
<!-- Forte4J_TLDX: This comment contains code generation information. Do not delete.
<tldx>
<tagHandlerGenerationRoot>classes</tagHandlerGenerationRoot>
</tldx>
-->
<!-- A validator verifies that the tags are used correctly at JSP
translation time. Validator entries look like this:
<validator>
<validator-class>com.mycompany.TagLibValidator</validator-class>
<init-param>
<param-name>parameter</param-name>
<param-value>value</param-value>
</init-param>
</validator>
-->
<!-- A tag library can register Servlet Context event listeners in
case it needs to react to such events. Listener entries look
like this:
<listener>
<listener-class>com.mycompany.TagLibListener</listener-class>
</listener>
-->
<tag>
<name>showProjectInfo</name>
<tag-class>mil.usaf.rad.metrics.report.showProjectInfoTag</tag-class>
<body-content>empty</body-content>
<description>Shows the basic project information</description>
</tag>
<tag>
<name>showProjectTeam</name>
<tag-class>mil.usaf.rad.metrics.report.showProjectTeamTag</tag-class>
<body-content>empty</body-content>
</tag>
<tag>
<name>showProjectHistory</name>
<tag-class>mil.usaf.rad.metrics.report.showProjectHistoryTag</tag-class>
<body-content>empty</body-content>
</tag>
</taglib>Next, here is the relevant section of web.xml that defines this taglib:
<taglib>
<taglib-uri>/WEB-INF/report.tld</taglib-uri>
<taglib-location>/WEB-INF/report.tld</taglib-location>
</taglib>Next, the code for showProjectTeamTag.java:
* showProjectTeam.java
* Created on March 9, 2005, 10:46 AM
package mil.usaf.rad.metrics.report;
import java.io.*;
import java.sql.*;
import java.lang.Integer;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* @author jason.ferguson
public class showProjectTeamTag extends TagSupport
public showProjectTeamTag()
super();
public int doAfterBody() throws JspException
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
int pr_id = Integer.parseInt(req.getParameter("pr_id"));
JspWriter out = pageContext.getOut();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
out.print("test");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Metrics");
catch (Exception e)
throw new JspException(e.getMessage());
String queryGetTeam = "SELECT Projects.pr_id, Accounts.name AS Name, Sum(Schedule.hours) AS SumOfhours FROM tblTAAccounts AS Accounts INNER JOIN ((tblTAScheduleEntries AS Schedule INNER JOIN tblProjectRelease AS ProjectRelease ON Schedule.projectID = ProjectRelease.tblFKTimeAccntProject) INNER JOIN tblPMProjects AS Projects ON ProjectRelease.Release_ID = Projects.pr_id) ON Accounts.accountID = Schedule.accountID WHERE Projects.pr_id=" + pr_id + " GROUP BY Projects.pr_id, Accounts.name, ProjectRelease.Release_number, Projects.Project_name";
try
out.print(queryGetTeam);
stmt = conn.createStatement();
rs = stmt.executeQuery(queryGetTeam);
if (rs == null)
out.print("No Results!");
out.print("<table>\n");
out.print("<tr>\n");
out.print("<th>Name</th>\n");
out.print("<th>Total Hours</th>\n");
out.print("</tr>\n");
while(rs.next())
out.print("<tr>\n");
out.print("<td>" + rs.getString("Name") + "</td>\n");
out.print("<td>" + rs.getInt("SumOfhours") + "</td>\n");
out.print("</tr>\n");
out.print("</table>\n");
rs.close();
stmt.close();
conn.close();
catch (Exception e)
throw new JspException(e.getMessage());
return SKIP_BODY;
}Finally, projectdetail.jsp, where the tag is called:
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="java.lang.Integer" %>
<%@taglib uri="/WEB-INF/report.tld" prefix="report" %>
<html>
<head><title>Project Detail</title></head>
<body>
<h1 align="center">Project Status</h1>
<h3>Project Description</h3>
<report:showProjectInfo />
<h3>Team Members</h3>
<report:showProjectTeam />
</body>
</html>The first tag, <report:showProjectInfo />, works fine. However, I get no output whatsoever when the system encounters <report:showProjectTeam />. I am a relative newbie at this, so any help is appreciated.
JasonIt doesnt seem to matter if the code is in doStartTag(), doEndTag(), orr any of the other functions.
I also put, as the first item in the function:
System.out.println("TEST");Nothing.
Just as an aside, here is the code for the <prefix:showProjectInfo />. Maybe I made a mistake in it? I closed the resultset and connection...
import java.io.*;
import java.sql.*;
import java.lang.Integer;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
* @author jason.ferguson
public class showProjectInfoTag extends BodyTagSupport
public int doEndTag() throws JspException
HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
int pr_id = Integer.parseInt(req.getParameter("pr_id"));
JspWriter out = pageContext.getOut();
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:Metrics");
catch (Exception e)
throw new JspException(e.getMessage());
String queryProjectInfo = "SELECT * FROM tblPMProjects WHERE pr_id=" + pr_id;
try
stmt = conn.createStatement();
rs = stmt.executeQuery(queryProjectInfo);
while (rs.next())
out.print("<table border=\"1\" style=\"border-collapse:collapse\">\n");
out.print("<tr>\n");
out.print("<td><b>Project Name:</b>" + rs.getString("Project_name") + "</td>\n");
out.print("<td align=\"right\"><b>RAD Number:</b>" + rs.getString("tblProjectNumber") + "</td>\n");
out.print("</tr>\n");
out.print("<tr>\n");
out.print("<td>Project description: " + rs.getString("Project_description") + "</td>\n");
out.print("</tr>\n");
out.print("<tr>\n");
out.print("<td>Customer: " + rs.getString("Customer_POC") + "</td>");
out.print("<tr>\n");
out.print("<tr>\n");
out.print("<td>Customer Unit: " + rs.getString("Customer_OFC") + "</td>\n");
out.print("</tr>\n");
out.print("<tr>\n");
out.print("<td>Customer Phone: " + rs.getString("Customer_phone") + "</td>\n");
out.print("</tr>\n");
out.print("</table>\n");
rs.close();
stmt.close();
conn.close();
catch (Exception e)
throw new JspException(e.getMessage());
finally
//conn.close();
return SKIP_BODY; -
Hi All,
Please tell me what is differnce between javabean and custom tags.
thank you.Javabean is a data object (or a data holder) whose properties can be accessed using getters, setters - ex getName() and setName()
JSP custom tags are merely Java classes that implement special interfaces (Tag interface). Once they are developed and deployed, their actions can be called from your HTML using XML syntax. Refer the article http://java.sun.com/developer/technicalArticles/xml/WebAppDev3/
Cheers,
Janesh -
Hi
I am new in jsp?s custom tag development and trying to run it's example with jakarta-tomcat-4.1.30. I have hello.jsp
<%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="first" %>
<HTML>
<HEAD> <TITLE>hELLO tAG</TITLE></HEAD>
<BODY bgcolor="#ffffcc"><B>My first tag prints</B>
<first:hello/></HTML>
and mytaglib.tld as
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib PUBLIC "-//Sun MicroSystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.2</jspversion>
<shortname></shortname>
<uri></uri>
<info>A simple tag library for the example</info>
<tag>
<name>hello</name>
<tagclass>HelloTag</tagclass>
<bodycontent>empty</bodycontent>
<info></info>
</tag>
</taglib>
and HelloTag.java as
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.Tag;
public class HelloTag implements Tag {
private PageContext pageContext;
private Tag parent;
public HelloTag() {
super(); }
public void setPageContext(PageContext arg0) {
this.pageContext = arg0;}
public void setParent(Tag arg0) {
this.parent = arg0;}
public Tag getParent() {
return parent;}
public int doStartTag() throws JspException {
try{
pageContext.getOut().print("This is my first Tag");
}catch(Exception e){throw new JspException("Error);}
return SKIP_PAGE; }
public int doEndTag() throws JspException {
return SKIP_PAGE;}
public void release() { }
I am getting following error
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /hello.jsp(7,0) Unable to load class hello
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:219)
at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:712)
at org.apache.jasper.compiler.Parser.parseElements(Parser.java:804)
at org.apache.jasper.compiler.Parser.parse(Parser.java:122)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:199)
at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
Can anyone help me in running this example.an uri is not an url,
in your web.xml you should have something like
<taglib>
<taglib-uri>http://yourtaglib/taglib</taglib-uri>
<taglib-location>/WEB-INF/yourtaglibtld</taglib-location>
</taglib>
that uri should be same as in the tld.file and same as in the <%@ taglib tag -
How to access variables passed in custom tag body
I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
<myTags:display> someVariable </myTags:display>
Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
Question 2:
I want to call the tags from main.jsp like:
<% String var1 = "Display Me Please"; %>
<myTags:display var1 />I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
<jsp:doBody var="theBody" />
<% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".
Edited by: coolkomal on Jun 3, 2009 7:45 AMcoolkomal wrote:
I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
<myTags:display> someVariable </myTags:display>
Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
<myTags:display var="<%=someVariable>"/> is a valid syntax for performing respective action of that variable. You can also use EL to pass the variable ${someVariable} provided the custom tag provide support for EL.
>
Question 2:
I want to call the tags from main.jsp like:
<% String var1 = "Display Me Please"; %>
<myTags:display var1 />
Just ensure that you declare all the related variables in Main.jsp and statically include Main.jsp in your jsp such that you do the checking
[http://java.sun.com/products/jsp/tags/11/syntaxref117.html]
>
I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
<jsp:doBody var="theBody" />
<% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".Can be done provided you code it the right way. Start learning basics of how to create custom taglibraries to gain more knowledge on how things can be managed.
[http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html] -
HTTP 500 Internel server error in Custom tag program on Weblogic 8.1
Dear sir,
Please attend my problem...
I face the Error 500 Internel server error when I rum the custom tag program on weblogic 8.1.
My program Structure is:
Program>Home.jsp
>WEB-INF>classes>mypack>MyTag.java, MyTag.class
>tlds>taglib.tld
>web.xml
Home.jsp:
<%@ taglib uri="/WEB-INF/tlds/taglib" prefix="Kumar" %>
<Kumar:hello name="Vijay">
It is a Tag Body<br>
</neeraj:hello>
taglib.tld:
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<uri>/WEB-INF/tlds/taglib</uri>
<tag>
<name>hello</name>
<tag-class>mypack.MyTag</tag-class>
<attribute>
<name>name</name>
<required>true</required>
</attribute>
</tag>
</taglib>
MyTag.java:
package mypack;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class MyTag extends TagSupport
String name;
public void setName(String c)
name=c;
public int doStartTag()
return EVAL_BODY_INCLUDE;
public int doEndTag()
try
JspWriter out=pageContext.getOut();
out.print("Good Night "+name);
catch(Exception e)
return EVAL_PAGE;
web.xml:
<web-app>
<welcome-file-list>
<welcome-file>/Home.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>/WEB-INF/tlds/taglib</taglib-uri>
<taglib-location>/WEB-INF/tlds/taglib.tld</taglib-location>
</taglib>
</web-app>
Allthough this program are run on NetBean6.1.In NetBean6.1, i am not specify the web.xml file.Please Help me..With an [HTTP status code|http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html] of 500, the most helpful information for debugging the problem is usually in the server's log file. There should be a stack trace in the web or application server's log file that will contain the specific root cause of this. It is often a NullPointerException or ClassNotFoundException or other "common" exception.
-
Custom Tag Capitalization Problem..
All,
OS: Windows 2000
App Server: Weblogic 6.0 sp 2
JDK: 1.3 (and tried 1.3.1)
I have a set of custom tags that run fine when I use them on an app server (such as Enhydra) with JDK 1.2.2, but when I switch to JDK 1.3.x, which weblogic 6.x requires, they suddenly start generating errors with attributes which have capitalized letters in them. For example, in my taglib I have:
<attribute>
<name>closeConnection</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
and in the support class I have:
* Get the value of closeConnection.
* @return value of closeConnection.
public boolean getCloseConnection() {
return closeConnection;
* Set the value of closeConnection.
* @param v Value to assign to closeConnection.
public void setCloseConnection(String v) {
if(v.toUpperCase().equals("TRUE")){
this.closeConnection = true;
} else {
this.closeConnection = false;
When I go to the page that this tag is on, I get the following output:
Parsing of JSP File '/index.jsp' failed:
/index.jsp(1): Error in using tag library uri='/cwerks' prefix='cwerks': There is no setter method for property 'closeconnection', for Tag class 'net.cwerks.taglib.MyTag'
probably occurred due to an error in /index.jsp line 1:
<%@ taglib uri="/cwerks" prefix="cwerks" %>
Thu Aug 02 19:06:52 PDT 2001
Note that the 'closeconnection' is all lowercase despite the fact that it is upper case in the tld and in the class itself.
I came across a similar problem in weblogic 5.1 when I upgraded from JDK 1.2.2 to JDK 1.3. I tried changing the JDK for weblogic 6.0 sp 2 to 1.2.2, but a dll was missing. I also tried switching it to 1.3.1, but that did not help. It seems like introspection may have changed slightly between the two version. I'm shocked, and a bit suspicious, that I haven't seen this problem all over the newsgroups. Anyone else seen this?
Thank you,
Carson Gross
[email protected]
[att1.html]
A solution presents itself:
The problem was NOT with capitalization. Instead, the problem was as
follows:
My method was for setting a boolean, but I took a string so that people
wouldn't have to type:
<mytags:tag foo="<%=true%>" />
instead, they could type:
<mytags:tag foo="true" />
which would call the setter method with a string "true", which would be then
converted to a boolean within my class.
So my setter has this signature:
public void setFoo(String s)
and my getter has this signature:
public boolean getFoo() /* I know this isn't standard, but isFoo doesn't
sound good to me*/
I can't tell if it's because JavaBeans changed slightly between jdk 1.2.2
and 1.3.x, or if Weblogic changed the way that they do things (I suspect the
latter, since I had things working fine in WL 5.2 w/ jdk 1.2.2 and then
things broke with WL 5.2 w/ jdk 1.3), but this no longer returns foo as a
valid property to be set, and since weblogic 6.x relies on JavaBeans,
instead of straight up introspection, it barfs. (I found this out by using
jad/emacs, a wicked combination for those who want to poke around in jars).
Anyway, I hope I can save someone else who has this same, albeit
specialized, problem a lot of pain by my discovery. Your getters and
setters better be of the same type with custom tags, or weblogic w/ jdk1.3.x
is gonna barf when parsing the tld.
Cheers, and thank God that's behind me,
Carson Gross
[email protected]
====================================================
"Carson Gross" <[email protected]> wrote in message
news:[email protected]...
The plot grows thicker...
The tags work fine on Tomcat 3.2.2
I deploy the example tags that came with wl60 that have more than one
capital letter in thier attributes, and they work fine. But my tag library
stubbornly insists on not working so long as I keep the attributes with more
than one capital letter in. If I remove the offending attributes, or change
them to have only one capital letter, they work, but this is not an
acceptable solution. (I guess.)
I even created an simple introspection class to make sure that the acutal
methods were there. They were.
I am at a complete loss here... I guess it's tomcat for now.
Cheers,
Carson Gross
[email protected]
"Carson Gross" <[email protected]> wrote in message
news:[email protected]...
All,
OS: Windows 2000
App Server: Weblogic 6.0 sp 2
JDK: 1.3 (and tried 1.3.1)
I have a set of custom tags that run fine when I use them on an app server
(such as Enhydra) with JDK 1.2.2, but when I switch to JDK 1.3.x, which
weblogic 6.x requires, they suddenly start generating errors with attributes
which have capitalized letters in them. For example, in my taglib I have:
<attribute>
<name>closeConnection</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
and in the support class I have:
* Get the value of closeConnection.
* @return value of closeConnection.
public boolean getCloseConnection() {
return closeConnection;
* Set the value of closeConnection.
* @param v Value to assign to closeConnection.
public void setCloseConnection(String v) {
if(v.toUpperCase().equals("TRUE")){
this.closeConnection = true;
} else {
this.closeConnection = false;
When I go to the page that this tag is on, I get the following output:
Parsing of JSP File '/index.jsp' failed:
/index.jsp(1): Error in using tag library uri='/cwerks' prefix='cwerks':
There is no setter method for property 'closeconnection', for Tag class
'net.cwerks.taglib.MyTag'
probably occurred due to an error in /index.jsp line 1:
<%@ taglib uri="/cwerks" prefix="cwerks" %>
Thu Aug 02 19:06:52 PDT 2001
Note that the 'closeconnection' is all lowercase despite the fact that it is
upper case in the tld and in the class itself.
I came across a similar problem in weblogic 5.1 when I upgraded from JDK
1.2.2 to JDK 1.3. I tried changing the JDK for weblogic 6.0 sp 2 to 1.2.2,
but a dll was missing. I also tried switching it to 1.3.1, but that did not
help. It seems like introspection may have changed slightly between the two
version. I'm shocked, and a bit suspicious, that I haven't seen this
problem all over the newsgroups. Anyone else seen this?
Thank you,
Carson Gross
[email protected]
-
Hi,
I have a custom tag that invokes sendRedirect() in the doAfterBody(). I'm curious
as to why the redirection output is not complete. Here's what I always got:
start of output ---------------------------------
HTTP/1.1 302 Moved Temporarily
Location: http://xenon:7001/ctl/error?WebLogicSession=OtCL5lprXh5wN0S5JJF4GFsDfU
BKZk40AQ8mluIVsHKw2TcG5xpz|6804183543513756739/167846717/6/7001/7001/7002/7002/7
001/-1
Server: WebLogic 5.1.0 Service Pack 8 12/20/2000 16:34:54 #95137
Content-Length: 481
Content-Type: text/html
Set-Cookie: WebLogicSession=OtCL5lprXh5wN0S5JJF4GFsDfUBKZk40AQ8mluIVsHKw2TcG5xpz
|6804183543513756739/167846717/6/7001/7001/7002/7002/7001/-1; path=/
Connection: Close
<html><head><title>302 Moved Temporarily</title></head>
<body bgcolor="#FFFFFF">
<p>This document you reque
-- end of output-------------
As you can see, the Content Length is huge compared to the incomplete returned
document.
Can anyone help please?
Thanks,
Iwan
you can pass the response object as argument to your
method..Thanks for your response!
Unfortunately I can't change the doEndTag() method parameters as doEndTag() is defined in the Tag interface. But if you mean pass the response object as an attribute of the tag i suppse that is possible.
However, that's pretty close to the hack I currently have to work around this problem except I'm putting the response object in a request attribute in the page and then retrieving it in the doEndTag() method.
But I am after something a little cleaner than either of these options..... I'm hoping I can just get the response object from another object I have access to. Any more thoughts? -
Hi,
I have couple of questions in Custom Libraray Tags:
1) How I can from Tag Java file to open a new JSP window without the toolbars and determine the window size.
2) How I can read a JSP parameter from Tag Java file. For example I have a field called "x" in JSP is not connected to the TAG by setAttribute.
3) How I can pass a dynamic value to custom tag. <route:routeList agentID = "1" >
how I can change the "1" to a field. When I change it to: <route:routeList agentID = "<%=request.getParameter("agentID")%>" > or to <route:routeList agentID = <%=request.getParameter("agentID")%> > I get empty value, even though the field has a value.
Thank you ...[email protected] ... Well, if you put something as an attribute in the pageContext object, you can get it... same as request or session scope attributes, but I thought the OP meant to do this (I guess not, though.. see below):
<%
String str = "...";
%>
<mytag:stuff .... />
And within the stuff tag, use str as a variable. I don't believe that's possible, because the compiled page in effect becomes like this:
String str = "...";
doStuffTag(whatever the parameters are);
Obviously that's not the right naming for the tag, but you get the idea...
JavaUserProg....
2) First, it's best to put quotes around the tag attributes...
<INPUT readOnly style="WIDTH: 84px; HEIGHT: 22px" name="operation[<%= lineNum%>"] value="<%=operation%>">
Second, do you mean you want to read from the tag what the HTML input field has in it? First, you have to submit the form, then the call request.getParameter("fieldname") to get the value. Otherwise, I'm not clear on what you are really trying to do.
3) If the field in the tag is an int field: setAgentID(int)
Then you can define the tag value as:
<mytag:stuff agentID="1" />
or
<% int aid = 1; %>
<mytag:stuff agentID="<%= aid %>" />
If you just put a static string value like the first way, it converts it. If you put an expression, the expression has to match the type of value it really is. So int for int, String for String, Collection for Collection. -
Escaping field value in custom transaction
I have created a custom transaction inserting fields in a table called `billing`. The values are taken mainly from two other tables called `account` and `paypalinfo`. I have attached the code below.
Please not the values to be inserted notated in wavy brackets like{paypalinfo.txnid}. This means the variable content is replacing what is in between the brackets and the brackets themselves of course at run time. Sine these are often character strings, I have put them into single quotes.
This worked great until I had an Irish guy acccessing my site with the sirname of O'Hara. That of course confused the statement, as suddenly there was a ' character, which was supposed to be interpreted as string, but was interpreted as SQL field delimiter and thus broke the code.
Here is my question: Should I escape the value and how would I do it, since this is not a normal code but a placeholder replaced at runtime? Or should I use another SQL field value delimiter, thus replace ' with ` ? I think the latter solution is inferior - just think of what heappens if you get an O`Hara instead of an O'Hara.
So in essence the question is: How do you handle escaping varabiable content in custom transactions with run time replaced variables in {...} brackets?
Any feedback welcome.
Here is the code:
// Make a custom transaction instance
$customTransaction2 = new tNG_custom($conn_chilli);
$tNGs->addTransaction($customTransaction2);
// Register triggers
$customTransaction2->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
// Set custom transaction SQL
$customTransaction2->setSQL("INSERT INTO billing (buyer_email, account, affiliate, partner, admin, transid, transdate, buyer_fname, buyer_lname, package, minutesbought, amountpaid, currency, userid, mac, nasid, routermac) values ('{paypalinfo.buyer_email}','{paypalinfo.account}','{account.affiliate}', '{account.partner}', '{account.admin}', '{paypalinfo.txnid}', '".$right_now."', '{paypalinfo.firstname}', '{paypalinfo.lastname}', '{paypalinfo.itemname}', '{package.tavail}', '{paypalinfo.mc_gross}', '{paypalinfo.mc_currency}', '{SESSION.id}', '{paypalinfo.usermac}', '".$router_name."', '{paypalinfo.routermac}')");You should never be using anything but:<br /><br />'b string mysql_real_escape_string ( string $unescaped_string [, resource $link_identifier ] )<br /><br />'i http://www.php.net/manual/en/function.mysql-real-escape-string.php<br /><br />The reasons for this is that this are related to SQL injection attacks. I would hand code this, but for anything more complex than CRUD ( http://en.wikipedia.org/wiki/Create,_read,_update_and_delete ) (which ADDT handles very nicely) I favor hand coding as it is faster, less complex when enforcing business process. Also, this allows one usage of the database management system's transaction mechanisms which are typically far more robust and reliable on top of being simpler to work with. <br /><br />Please note that the type of my storage for your database within MySQL will support different features. To enable the usage of database transactions you will need to use the InnoDB table type rather then the default MyISAM table type. Various versions of MySQL have other options for transaction safe table but those two are the ones that are consistently available in web environs where bleeding edge software is not normally deployed.<br /><br />http://dev.mysql.com/doc/refman/5.0/en/storage-engines.html<br /><br />Diatribe aside, what you need to do with these templated objects is to duplicate the object referenced {paypalinfo} and apply mysql_real_escape_string to the duplicates elements {paypalinfo_escaped_copy.txnid}. Then run the copied ADDT code with values from {paypalinfo_escaped_copy}. How you do you this I leave you to track down as I do not find that level of abstraction to be a good use of my time and other other libraries/frameworks do it much more elegantly using less of my time.<br /><br />But as Gunter already noted, refactoring your problem to work with your tools existing architectures can be simpler. ADDT has a limited programming architecture (primary design) which is done to simplify the automatic generation of code. This can make some simple things complex (50-80 mouse clicks) as opposed to typing one or two lines of code.<br /><br />some thoughts, <smile><br /><br />Sean
-
Hi,
I am trying to develop a custom tag for Marquee in JSF, my usecase is to display a value from managed bean(Dynamically). please find the code below and guide me where i have made mistake
regards
Sandeep
Component class:
package customtags;
import javax.el.ValueExpression;
import javax.faces.component.UIComponentBase;
import javax.faces.context.FacesContext;
public class Marquee extends UIComponentBase {
public static final String COMPONENT_TYPE = "marqueecomp";
public static final String RENDERER_TYPE = "marqueeRenderer";
private Object[] _state = null;
private String value;
public String getValue() {
if (null != this.value) {
return this.value;
ValueExpression _ve = getValueExpression("value");
return (_ve != null) ? (String) _ve.getValue(getFacesContext()
.getELContext()) : null;
public void setValue(String marquee) {
this.value = marquee;
public String getFamily() {
// TODO Auto-generated method stub
return COMPONENT_TYPE;
// public void encodeBegin(FacesContext context) throws IOException {
// ResponseWriter writer = context.getResponseWriter();
// writer.startElement("marquee", this);
// writer.write(getValue());
// writer.endElement("marquee");
public void restoreState(FacesContext context, Object state) {
this._state = (Object[]) _state;
super.restoreState(_context, this._state[0]);
value = (String) this._state[1];
public Object saveState(FacesContext _context) {
if (_state == null) {
_state = new Object[2];
state[0] = super.saveState(context);
_state[1] = value;
return _state;
Tag Class:
package customtags;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.webapp.UIComponentELTag;
public class MarqueeTag extends UIComponentELTag {
protected ValueExpression marquee;
public String getComponentType() {
// TODO Auto-generated method stub
return Marquee.COMPONENT_TYPE;
public String getRendererType() {
// TODO Auto-generated method stub
return Marquee.RENDERER_TYPE;
* protected void setProperties(UIComponent component) {
* super.setProperties(component); Marquee marqComp = (Marquee) component;
* if (marquee != null) { marqComp.setValue(marquee); } }
protected void setProperties(UIComponent component) {
super.setProperties(component);
Marquee marqComp = null;
try {
marqComp = (Marquee) component;
} catch (ClassCastException cce) {
throw new IllegalStateException(
"Component "
+ component.toString()
+ " not expected type. Expected: com.foo.Foo. Perhaps you're missing a tag?");
if (marquee != null) {
//marqComp.setValueExpression("value", marquee);
marqComp.setValue("fsdfsdfsdfsdfsd");
* @return the marquee
public ValueExpression getMarquee() {
return marquee;
* @param marquee
* the marquee to set
public void setMarquee(ValueExpression marquee) {
this.marquee = marquee;
*.tld file*
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<tlib-version>1.0</tlib-version>
<short-name>marqueecomp</short-name>
<uri>http://tags.org/marquee</uri>
<tag>
<name>marqueeTag</name>
<tag-class>customtags.MarqueeTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description><![CDATA[Your description here]]></description>
<name>id</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description><![CDATA[Your description here]]></description>
<name>value</name>
</attribute>
</tag>
</taglib>
Renderer class:
package customtags;
import java.io.IOException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
public class MarqueeRenderer extends Renderer {
public void encodeBegin(final FacesContext facesContext,
final UIComponent component) throws IOException {
super.encodeBegin(facesContext, component);
final ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement("DIV", component);
/*String styleClass =
(String)attributes.get(Shuffler.STYLECLASS_ATTRIBUTE_KEY);
writer.writeAttribute("class", styleClass, null);*/
public void encodeEnd(final FacesContext facesContext,
final UIComponent component) throws IOException {
final ResponseWriter writer = facesContext.getResponseWriter();
writer.endElement("DIV");
in Faces-Config:
<component>
<display-name>marqueecomp</display-name>
<component-type>marqueecomp</component-type>
<component-class>customtags.Marquee</component-class>
<component-extension>
<renderer-type>marqueeRenderer</renderer-type>
</component-extension>
</component>
<render-kit>
<renderer>
<component-family>marqueecomp</component-family>
<renderer-type>marqueeRenderer</renderer-type>
<renderer-class>customtags.MarqueeRenderer</renderer-class>
</renderer>
</render-kit>
In class path --->marquee.taglib.xml
<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC
"-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
"http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
<facelet-taglib>
<namespace>http://tags.org/marquee</namespace>
<tag>
<tag-name>marqueeTag</tag-name>
<component>
<component-type>marqueecomp</component-type>
<renderer-type>marqueeRenderer</renderer-type>
</component>
</tag>
</facelet-taglib>
*.xhtml file*
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich" xmlns:mycomp="http://tags.org/marquee">
<head>
<title>DEBTDOC Home Page</title>
<meta http-equiv="keywords" content="enter,your,keywords,here" />
<meta http-equiv="description"
content="A short description of this page." />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/common.css"></link>
<script language="javascript" src="../script/common.js"></script>
</head>
<body>
<f:view>
<mycomp:marqueeTag value="hello World"></mycomp:marqueeTag>There exist the JSTL SQL taglib, but I don't recommend this. It should only be used for quick development and testing. For database connectivity, rather create a data layer with DAO classes which you on its turn just plug in your business layer (with servlets).
Maybe you are looking for
-
I've checked my about:config settings beforehand since I hear the setting for this is usually in there. It's still the same and hasn't been changed. As far as I know, I haven't downloaded any add-ons recently that would cause this change. None have b
-
Can't boot into Mac OS after Windows install via Bootcamp
Hello. Last night I installed Windows 7 on my Macbook Pro early 2011 via Bootcamp.After some major complications I was able to finally install Windows 7 and boot into it. Now I can't boot back into my "Macintosh HD" partition, it shows a no entry sig
-
Why won't Colorfly C3 MP3/WAV player appear on my OSX 10.9.5 desktop?
Hello. I've just bought a Colorfly C3 MP3/WAV player. It won't appear on my OSX 10.9.5 (Maverick) desktop - but will appear on the desktop of an older computer running Snow Leopard. As all my music is in iTunes on my Maverick OS - I need it to work o
-
Photoshop Elements 10 Error Code
Every time I try to launch the elements 10 editor I get the error code "The specified module could not be found." I cannot re-install the program because it came pre-installed on my computer. My computer is a HP envy m6 with windows 8 64bit.
-
Horrible Bluetooth Keyboard Battery Life - Since Magic Mouse?
I'm having a weird issue that is driving me nuts. I've noticed that over the past couple weeks I've had to replace the batteries in my Apple bluetooth keyboard several times because it is draining at a rate of about 18-20% a day, even when I'm not at