用eclipse开发项目,tomcat为web server.
1. 配置项目在server.xml中
<Context docBase="wishone" path="/" reloadable="true" source="org.eclipse.jst.jee.server:wishone"/>
这样访问自己的项目,将没有web名称的context, 例如: 127.0.0.1/login
2. 在tomcat/conf/context.xml中添加数据源配置
<Resource name="jdbc/your jndi" auth="Container" type="javax.sql.DataSource"
initialSize="10" maxActive="100" maxIdle="30" maxWait="10000"
username="*" password="*" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/youdblink"
validationQuery="SELECT 1" testOnBorrow="true"/>
3. 在项目的web.xml中添加
<resource-ref>
<description>JNDI DataSource</description>
<res-ref-name>jdbc/wishone</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>