蓝
蓝色虾
Unregistered / Unconfirmed
GUEST, unregistred user!
工程文件建立在:G:/vod/Vod目录下
web.xml文件位于:G:/vod/Vod/defaultroot/WEB-INF
我的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>servlet1</servlet-name>
<servlet-class>vod.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<resource-ref>
<description>Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file.</description>
<res-ref-name>jdbc/MysqlDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
我在位于D:/JBuilder7/jakarta-tomcat-4.0.3/conf目录中的server.xml文件的末尾标签</Server>
之前插入
<!-- 数据库连接池的配置 -->
<Context path=""do
cBase="G:/Vod/defaultroot/" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/Test" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MysqlDB">
<parameter>
<name>user</name>
<values>DateBase</values>
</parameter>
<parameter>
<name>password</name>
<values>sailing</values>
</parameter>
<parameter>
<name>driverClassName</name>
<values>org.gjt.mm.mysql.Driver</values>
</parameter>
<parameter>
<name>driverName</name>
<values>jdbc:mysql://localhost/gdmovie</values>
</parameter>
</ResourceParams>
</Context>
我的Servlet1的内容为,在jb7中执行run时的URL为:http://localhost:8080/servlet1
package vod;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import java.sql.Connection;
public class Servlet1 extends HttpServlet {
static final private String CONTENT_TYPE = "text/html";
Connection conn;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public voiddo
Get(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/MysqlDB");
//conn=ds.getConnection();
if(ds!=null)
out.println("Connection is OK!");
else
out.println("Fail!");
}catch(Exception ne){ out.println(ne);}
}
}
请问为何我每次执行结果都为Fail! ?
我已经阅读过了相关的文章,他们都是将文件拷贝到tomcat的webapps下面运行
的,我希望能够在其他的目录也能使用,但是经过多次尝试均告失败。
解答者本人定100分奉上。
web.xml文件位于:G:/vod/Vod/defaultroot/WEB-INF
我的web.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>servlet1</servlet-name>
<servlet-class>vod.Servlet1</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servlet1</servlet-name>
<url-pattern>/servlet1</url-pattern>
</servlet-mapping>
<resource-ref>
<description>Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file.</description>
<res-ref-name>jdbc/MysqlDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
我在位于D:/JBuilder7/jakarta-tomcat-4.0.3/conf目录中的server.xml文件的末尾标签</Server>
之前插入
<!-- 数据库连接池的配置 -->
<Context path=""do
cBase="G:/Vod/defaultroot/" debug="0" reloadable="true" crossContext="true">
<Resource name="jdbc/Test" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/MysqlDB">
<parameter>
<name>user</name>
<values>DateBase</values>
</parameter>
<parameter>
<name>password</name>
<values>sailing</values>
</parameter>
<parameter>
<name>driverClassName</name>
<values>org.gjt.mm.mysql.Driver</values>
</parameter>
<parameter>
<name>driverName</name>
<values>jdbc:mysql://localhost/gdmovie</values>
</parameter>
</ResourceParams>
</Context>
我的Servlet1的内容为,在jb7中执行run时的URL为:http://localhost:8080/servlet1
package vod;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.Context;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import java.sql.Connection;
public class Servlet1 extends HttpServlet {
static final private String CONTENT_TYPE = "text/html";
Connection conn;
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Get request
public voiddo
Get(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
DataSource ds = null;
try{
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
ds = (DataSource)envCtx.lookup("jdbc/MysqlDB");
//conn=ds.getConnection();
if(ds!=null)
out.println("Connection is OK!");
else
out.println("Fail!");
}catch(Exception ne){ out.println(ne);}
}
}
请问为何我每次执行结果都为Fail! ?
我已经阅读过了相关的文章,他们都是将文件拷贝到tomcat的webapps下面运行
的,我希望能够在其他的目录也能使用,但是经过多次尝试均告失败。
解答者本人定100分奉上。