在tomcat6.0的context.xml文件中配置:
<Context>
<Resource name="jdbc/system" auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/system" />
</Context>在lib下的web.xml文件中配置:
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>login</servlet-name>
<servlet-class>servlet.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>jdbc/system</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
在servlet中的login页面中如下:
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
try {
Connection conn=(Connection)DatabaseConn.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from usertable");
if(rs.next()){
response.sendRedirect("index2.htm");
}
else{
response.sendRedirect("index.htm");
} }catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}public void init() throws ServletException {
}
}为何一直报错为Cannot load JDBC driver class'com.mysql.jdbc.Driver'只是一个登录过程
<Context>
<Resource name="jdbc/system" auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password=""
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/system" />
</Context>在lib下的web.xml文件中配置:
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>login</servlet-name>
<servlet-class>servlet.login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
<resource-ref>
<res-ref-name>jdbc/system</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
在servlet中的login页面中如下:
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
try {
Connection conn=(Connection)DatabaseConn.getConnection();
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from usertable");
if(rs.next()){
response.sendRedirect("index2.htm");
}
else{
response.sendRedirect("index.htm");
} }catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}public void init() throws ServletException {
}
}为何一直报错为Cannot load JDBC driver class'com.mysql.jdbc.Driver'只是一个登录过程
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货