访问是出现这个问题
Servlet DBE is not available
description The requested resource (Servlet DBE is not available) is not available.以下是文件原代码
package org.sunxin.lesson.jsp.ch21;import java.io.*;
import java.sql.*;import javax.servlet.*;
import javax.servlet.http.*;import org.apache.log4j.*;public class DBExceptionServlet extends HttpServlet
{
static Logger logger=Logger.getRootLogger();
static Logger bookLogger=Logger.getLogger("bookstoreLogger");
public void init() throws ServletException
{
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
if(file != null)
{
PropertyConfigurator.configure(prefix+file);
} try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ce)
{
throw new UnavailableException("加载数据库驱动失败!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException
{
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
if(file != null)
{
PropertyConfigurator.configure(prefix+file);
} try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ce)
{
throw new UnavailableException("加载数据库驱动失败!");
}
catch(Exception e)
{
e.printStackTrace();
}
Connection conn=null;
Statement stmt=null;
try
{
conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pubs","root","123456");
stmt=conn.createStatement();
stmt.executeUpdate("delete from jobs where job_id=13");
}
catch(SQLException se)
{
NDC.push(req.getRemoteHost());
logger.warn("数据库操作失败! "+se);
logger.error("数据库操作失败! "+se);
bookLogger.warn("数据库操作失败! "+se);
bookLogger.error("数据库操作失败! "+se);
NDC.pop();
NDC.remove();
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"数据库操作出现问题,请联系管理员。");
}
finally
{
if(stmt!=null)
{
try
{
stmt.close();
}
catch(SQLException se)
{
bookLogger.error("关闭Statement失败!",se);
}
stmt=null;
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException se)
{
bookLogger.error("关闭数据库连接失败!",se);
}
conn=null;
}
}
}
}
但是我把init给注释掉出现了
description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Wrapper cannot find servlet class org.sunxin.lesson.jsp.DBExceptionServlet or a class it depends on
说明我的web配置都没有问题,但我刷新几次它就出现没有注释的问题,请大家给说说可能是什么问题
说明:java1.6,tomact5.5.27,editplus.我在学习log4j。java中。tomact中share/lib 还有WEB-INF/lib下都放了log4j包
Servlet DBE is not available
description The requested resource (Servlet DBE is not available) is not available.以下是文件原代码
package org.sunxin.lesson.jsp.ch21;import java.io.*;
import java.sql.*;import javax.servlet.*;
import javax.servlet.http.*;import org.apache.log4j.*;public class DBExceptionServlet extends HttpServlet
{
static Logger logger=Logger.getRootLogger();
static Logger bookLogger=Logger.getLogger("bookstoreLogger");
public void init() throws ServletException
{
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
if(file != null)
{
PropertyConfigurator.configure(prefix+file);
} try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ce)
{
throw new UnavailableException("加载数据库驱动失败!");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,IOException
{
String prefix = getServletContext().getRealPath("/");
String file = getInitParameter("log4j-init-file");
if(file != null)
{
PropertyConfigurator.configure(prefix+file);
} try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch(ClassNotFoundException ce)
{
throw new UnavailableException("加载数据库驱动失败!");
}
catch(Exception e)
{
e.printStackTrace();
}
Connection conn=null;
Statement stmt=null;
try
{
conn=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/pubs","root","123456");
stmt=conn.createStatement();
stmt.executeUpdate("delete from jobs where job_id=13");
}
catch(SQLException se)
{
NDC.push(req.getRemoteHost());
logger.warn("数据库操作失败! "+se);
logger.error("数据库操作失败! "+se);
bookLogger.warn("数据库操作失败! "+se);
bookLogger.error("数据库操作失败! "+se);
NDC.pop();
NDC.remove();
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"数据库操作出现问题,请联系管理员。");
}
finally
{
if(stmt!=null)
{
try
{
stmt.close();
}
catch(SQLException se)
{
bookLogger.error("关闭Statement失败!",se);
}
stmt=null;
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException se)
{
bookLogger.error("关闭数据库连接失败!",se);
}
conn=null;
}
}
}
}
但是我把init给注释掉出现了
description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Wrapper cannot find servlet class org.sunxin.lesson.jsp.DBExceptionServlet or a class it depends on
说明我的web配置都没有问题,但我刷新几次它就出现没有注释的问题,请大家给说说可能是什么问题
说明:java1.6,tomact5.5.27,editplus.我在学习log4j。java中。tomact中share/lib 还有WEB-INF/lib下都放了log4j包
但我把init注释去掉为什么报Servlet DBE is not available
description The requested resource (Servlet DBE is not available) is not available.
(自己理解为:文件找不到)
如果没到断点检查配置
如果到了断点继续 看哪里出的错误
这就是这,把+se去掉就正常了,但这样失去意义了,我想要的就是出错相关信息
logger.warn("数据库操作失败! "+se);
logger.error("数据库操作失败! "+se);
bookLogger.warn("数据库操作失败! "+se);
bookLogger.error("数据库操作失败! "+se);
用se.printStackTrace();
再看看异常在哪一行出现的