我正在尝试将一个带有数据库功能的JSP添加到现有的Tomcat 5.5应用程序中(如果有帮助,应用名为GeoServer 2.0.0)。
该应用程序本身可以很好地访问Postgres数据库,所以我知道数据库是可用的,用户可以访问它,所有操作都正常。我正在尝试在我添加的JSP中进行数据库查询。我基本上直接使用了Tomcat datasource示例中的配置示例。必需的taglibs放置在正确的位置 - 如果只使用taglib引用,则不会出现任何错误,因此它能够找到这些JARs。Postgres JDBC驱动程序postgresql-8.4.701.jdbc3.jar位于$CATALINA_HOME/common/lib中。
以下是JSP的顶部:
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<sql:query var="rs" dataSource="jdbc/mmas">
select current_validstart as ValidTime from runoff_forecast_valid_time
</sql:query>
$CATALINA_HOME/conf/server.xml 中的相关部分,位于 <Engine>
内的 <Host>
中:
<Context path="/gs2" allowLinking="true">
<Resource name="jdbc/mmas" type="javax.sql.Datasource"
auth="Container" driverClassName="org.postgresql.Driver"
maxActive="100" maxIdle="30" maxWait="10000"
username="mmas" password="very_secure_yess_precious!"
url="jdbc:postgresql//localhost:5432/mmas" />
</Context>
这些行是在webapps/gs2/WEB-INF/web.xml文件的</taglib>标签中的最后一行:
<resource-ref>
<description>
The database resource for the MMAS PostGIS database
</description>
<res-ref-name>
jdbc/mmas
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
最后,异常情况:
exception
org.apache.jasper.JasperException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver"
[...wads of ensuing goo elided]