我在使用自定义标签时遇到问题。我收到此错误
/test.jsp (line: 10, column: 4) Unable to find setter method for attribute: url
这是代码:
TagHandlerClass:
package net.viralpatel.jsp.custom.taglib;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
public class SubstrTagHandler extends TagSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private String url;
private String videoId;
private String listId;
private boolean bOpenNewWindow;
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getVideoId() {
return videoId;
}
public void setVideoId(String videoId) {
this.videoId = videoId;
}
public String getListId() {
return listId;
}
public void setListId(String listId) {
this.listId = listId;
}
public boolean isbOpenNewWindow() {
return bOpenNewWindow;
}
public void setbOpenNewWindow(boolean bOpenNewWindow) {
this.bOpenNewWindow = bOpenNewWindow;
}
public int doStartTag() throws JspException {
try {
//Get the writer object for output.
JspWriter out = pageContext.getOut();
if (null != url && !url.trim().equals("")) {
StringBuffer resultURL = new StringBuffer();
resultURL.append("<a href=" + url);
//this is internal URL and not poiniting to dam so need to append .html
if (url.startsWith("/") && !url.contains("/dam/")) {
resultURL.append(".html");
}
if ((videoId != null && !videoId.trim().equals("")) || (listId != null && !listId.trim().equals(""))) {
if ((videoId != null && !videoId.trim().equals(""))) {
resultURL.append("?vcID=" + videoId);
} else if (listId != null && !listId.trim().equals("")) {
resultURL.append("?listID=" + listId);
}
}
if (bOpenNewWindow) {
resultURL.append(" target=_blank");
}
resultURL.append("></a>");
//Perform substr operation on string.
out.println(resultURL);
}
} catch (IOException e) {
e.printStackTrace();
}
return SKIP_BODY;
}
}
我的TLD文件:
<?xml version="1.0" encoding="UTF-8"?>
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>Sublink</shortname>
<info>Sample taglib for Video Link operation</info>
<tag>
<name>link</name>
<tagclass>net.viralpatel.jsp.custom.taglib.SubstrTagHandler</tagclass>
<info>Substring function.</info>
<attribute>
<name>url</name>
<required>false</required>
</attribute>
<attribute>
<name>videoId</name>
<required>false</required>
</attribute>
<attribute>
<name>listId</name>
<required>false</required>
</attribute>
<attribute>
<name>bOpenNewWindow</name>
<required>false</required>
</attribute>
</tag>
</taglib>
这是JSP文件
<%@taglib prefix="test" uri="/WEB-INF/lib/SubstrLink.tld"%>
<html>
<head>
<title>JSP Custom Taglib example: Substr function</title>
</head>
<body>
SUBSTR(GOODMORNING, 1, 6) is
<font color="blue">
<test:link url="www.google.com" videoId="1" listId="6" bOpenNewWindow="true"/>
</font>
</body>
</html>