为什么找不到setter方法?

whulph 2003-11-18 09:55:29
大家帮我看看这个Tag运行的时候为什么报这样的错呢:

TagHandler的源代码:

package station.auction.db.taglib;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class QueryTagHandler extends BodyTagSupport
{
protected Connection con=null;

public Connection getConnection()
{
return con;
}

public void setConnection(String newConnection)
throws JspException
{
try
{
con=(Connection)pageContext.findAttribute(newConnection);
}catch(Exception exc)
{
throw new JspException(exc.getMessage());
}
}

public int doAfterBody() throws JspException
{
try
{
String query=getBodyContent().getString();

//Create the statement and execute the query
Statement stmt=getConnection().createStatement();
ResultSet rs=stmt.executeQuery(query);
//Set the ResultSet in the page context
this.pageContext.setAttribute(getId(),rs,pageContext.PAGE_SCOPE);


}catch(Exception exc)
{
throw new JspException(exc.getMessage());
}
return SKIP_BODY;
}
}
对应tld文件中的片段为:

<tag>
<name>query</name>
<tag-class>station.auction.db.taglib.QueryTagHandler</tag-class>
<tei-class>station.auction.db.taglib.QueryTagExtraInfo</tei-class>
<body-content>JSP</body-content>
<description>Specifies a SQL query</description>
<attribute>
<name>id</name>
<required>true</required>
</attribute>
<attribute>
<name>connection</name>
<required>true</required>
</attribute>
</tag>
在daysevents_tag.jsp文件中引用query这个Tag:
<db:query id="eventsForDay" connection="conn">
SELECT name,description,start_date FROM Events
WHERE MONTH(start_date)=<%=month%>
AND YEAR(start_date)=<%=year%>
AND DAY(start_date)=<%=day%>
ORDER BY HOUR(start_date),MINUTE(start_date)
</db:query>
在tomcat中报错:
org.apache.jasper.JasperException: /111/daysevents_tag.jsp(27,1) Unable to find setter method for attribute: connection
但是我明明是有写setConnection(String newConnection)这个函数的啊,怎么回事呢?希望大家帮我看看啊!非常感谢!
...全文
42 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧