Java 如何配置TOMCAT7和MySql
TOMCAT7本地服务器有一个大问题。 我遵循这个指南=>。我这样做是为了: 1)Java 如何配置TOMCAT7和MySql,java,mysql,jsp,tomcat,Java,Mysql,Jsp,Tomcat,TOMCAT7本地服务器有一个大问题。 我遵循这个指南=>。我这样做是为了: 1) 将JDBC驱动程序的jar复制到$CATALINA_HOME/lib中。我的“$CATALINA_HOME/lib”在/usr/share/tomcat7/lib中(我想是的,我不确定)。我在那里复制了文件mysql-connector-java-5.1.38-bin.jar 2) 我创建了一个新的MySql用户,并遵循rest MySql指令: mysql> GRANT ALL PRIVILEGES ON
将JDBC驱动程序的jar复制到$CATALINA_HOME/lib中
。我的“$CATALINA_HOME/lib”在/usr/share/tomcat7/lib中(我想是的,我不确定)。我在那里复制了文件mysql-connector-java-5.1.38-bin.jar
2) 我创建了一个新的MySql用户,并遵循rest MySql指令:
mysql> GRANT ALL PRIVILEGES ON *.* TO javauser@localhost
-> IDENTIFIED BY 'javadude' WITH GRANT OPTION;
mysql> create database javatest;
mysql> use javatest;
mysql> create table testdata (
-> id int not null auto_increment primary key,
-> foo varchar(25),
-> bar int);
3) 我在以下模式下修改了context.xml
文件,该文件位于/var/lib/tomcat7/webapps/ROOT/META-INF
位置
<Context>
<!-- maxActive: Maximum number of database connections in pool. Make sure you
configure your mysqld max_connections large enough to handle
all of your db connections. Set to -1 for no limit.
-->
<!-- maxIdle: Maximum number of idle database connections to retain in pool.
Set to -1 for no limit. See also the DBCP documentation on this
and the minEvictableIdleTimeMillis configuration parameter.
-->
<!-- maxWait: Maximum time to wait for a database connection to become available
in ms, in this example 10 seconds. An Exception is thrown if
this timeout is exceeded. Set to -1 to wait indefinitely.
-->
<!-- username and password: MySQL username and password for database connections -->
<!-- driverClassName: Class name for the old mm.mysql JDBC driver is
org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
-->
<!-- url: The JDBC connection url for connecting to your MySQL database.
-->
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest"/>
</Context>
5) 然后,我在/var/lib/tomcat7/webapps/ROOT位置中创建了dir DBTEST,并在此处插入文件test.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/TestDB">
select id, foo, bar from testdata
</sql:query>
<html>
<head>
<title>DB Test</title>
</head>
<body>
<h2>Results</h2>
<c:forEach var="row" items="${rs.rows}">
Foo ${row.foo}<br/>
Bar ${row.bar}<br/>
</c:forEach>
</body>
</html>
然后(始终按照说明)我在var/lib/tomcat7/webapps/ROOT/META-INF
==>var/lib/tomcat7/webapps/ROOT/META-INF/lib
在这里面,我复制了4.jar文件
现在http://localhost:8080/DBtest/test.jsp
返回
The absolute uri: http://java.sun.com/jsp/jstl/sql cannot be resolved in either web.xml or the jar files deployed with this application
还有一次两个人回来
java.lang.ClassNotFoundException: org.apache.jsp.DBtest.test_jsp
jar进入
/lib
而不是/META-INF/lib
AFAIKThanks,我在/lib中复制了te 4文件*.jar(不是var/lib,只有lib)。也有同样的问题!4 files.jar是否正确?“/lib”我的意思是/var/lib/tomcat7/webapps/ROOT/WEB-INF/lib
,请参阅文档:抱歉,我不清楚:在ROOT目录中,我只有以下子目录:DBtest和META-INF
The absolute uri: http://java.sun.com/jsp/jstl/sql cannot be resolved in either web.xml or the jar files deployed with this application
java.lang.ClassNotFoundException: org.apache.jsp.DBtest.test_jsp