<sql:query id="eventsForDay" connection="con">
---》
这句话要求标签中要有一个为connection的属性设值的方法,即setConnection(String)

解决方案 »

  1.   

    package tag;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 int doAfterBody() throws JspException { try { String query = getBodyContent().getString(); System.out.println("[QueryTagHandler] doAfterBody, Query Body-> " + getBodyContent().getString()); Statement stmt = getConnection().createStatement(); ResultSet rs = stmt.executeQuery(query); this.pageContext.setAttribute(getId(), rs, pageContext.PAGE_SCOPE); } catch (Exception exc) { throw new JspException(exc.getMessage()); } return SKIP_BODY;}public Connection getConnection() { return con;}
    public void setConnection(String newConnection) throws JspException{try { System.out.println("[QueryTagHandler] setConnection, Attribute-> " + newConnection); con = (Connection) pageContext.getAttribute(newConnection);
    System.out.println("[QueryTagHandler] Connection : " + con); } catch (Exception exc) { throw new JspException(exc.getMessage()); }}}有setConnection(String)方法,为什么还是同样错误?!!!!!