为什么找不到setter方法?
大家帮我看看这个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)这个函数的啊,怎么回事呢?希望大家帮我看看啊!非常感谢!