Hi all,
Please help me with my TAG problem. I have been struggled with this
problem for a week now. At run time it give me this error message:
Location: /AuctionStation/daysevents.jsp
Internal Servlet Error:
javax.servlet.ServletException: Can't find a method to write
property 'connection' in a bean of
type 'station.auction.db.taglib.QueryTagHandler'
at org.apache.jasper.runtime.PageContextImpl.handlePageException
(PageContextImpl.java:386)
Down here is my code:
daysevents.jsp
<%@ page import="java.sql.*" %>
<%@ taglib uri="http://www.auction.station.net/db-taglib" prefix="db" %>
<html>
<body>
<db:connection id="conn" url="jdbc:odbc:auction" />
<db:query id="eventsForDay" connection = "con" >
SELECT name, description, start_date FROM Events
</db:query>
</body>
</html>
db-taglib.tld
<?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.1</jspversion>
<shortname>db</shortname>
<uri>http://localhost:8080/AuctionStation/jsp/mytags.jar</uri>
<info>Database Tag Library</info>
<tag>
<name>query</name>
<tagclass>station.auction.db.taglib.QueryTagHandler</tagclass>
<teiclass>station.auction.db.taglib.QueryTagExtraInfo</teiclass>
<bodycontent>JSP</bodycontent>
<info>Specifies a SQL query</info>
<attribute>
<name>id</name>
<required>true</required>
</attribute>
<attribute>
<name>connection</name>
<required>true</required>
</attribute>
</tag>
</taglib>
QueryTagHandler.java
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 {
public 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();
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;
}
Thank you in advance.
Myle Pham
}