我正在学习O'Reilly的“学习路径:使用Java进行企业Web编程”课程。我使用PostgreSQL重新编写了一个简单的webapp代码。我用Maven构建它并在Tomcat服务器上运行它。数据库已启动并填充。我收到以下错误:
javax.servlet.jsp.JspException:无法获取连接,DataSource无效:“java.sql.SQLException:找不到合适的$ {ourDS}驱动程序”
我发现它通常是没有postgres依赖的结果。我也尝试添加其他依赖项,如tomcat插件等。 我明白我错过了一小段依赖或某处文件,但我找不到它是什么。
主.jsp文件包含以下代码:
<%@ page errorPage = "error.jsp" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri = "http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<!DOCTYPE html>
<html>
<head>
<title>List of products in our database</title>
<link rel = "stylesheet" href = "style.css" type = "text/css"></link>
</head>
<body>
<sql:setDataSource
var = "ourDS"
driver = "org.postgresql.Driver"
url = "jdbc:postgresql://localhost:5432/skistuff"
user = "******"
password = "*******"
/>
<sql:query var = "productList" dataSource = "${ourDS}">
SELECT * FROM skisEtc ORDER BY id;
</sql:query>
<!-- Some kind of display -->
</body>
与讲师相反,我使用Maven而不是Ant,所以我必须以其他方式解决它。从课程中提到的,我准备了以下pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.training.skis</groupId>
<artifactId>skispagebasic</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>skispagebasic Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4.jre7</version>
</dependency>
</dependencies>
<build>
<finalName>skispagebasic</finalName>
</build>
</project>