部署在tomcat下的一个工程,工程里面的default.js调用了一个sc.jsp,后台日志时不时的就会报错,有哪位大神能不能帮偶看看问题出在哪哇
org.apache.tomcat.dbcp.dbcp.AbandonedTrace$AbandonedObjectException: DBCP object created 2013-04-28 00:03:53 by the following code was never closed:详细的报错代码如下:
org.apache.tomcat.dbcp.dbcp.AbandonedTrace$AbandonedObjectException: DBCP object created 2013-04-28 00:03:53 by the following code was never closed: at org.apache.tomcat.dbcp.dbcp.AbandonedTrace.setStackTrace(AbandonedTrace.java:139) at org.apache.tomcat.dbcp.dbcp.AbandonedObjectPool.borrowObject(AbandonedObjectPool.java:81) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) at org.apache.jsp.sc_jsp.getConnection(sc_jsp.java:35) at org.apache.jsp.sc_jsp.countbytitle(sc_jsp.java:45) at org.apache.jsp.sc_jsp._jspService(sc_jsp.java:173) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:1771) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
function countbytitle(titleurl){ var url = "http://localhost:8080/helpsearch/sc.jsp?q=" + cjkEncode(titleurl); var js_obj = document.createElement("script"); js_obj.type = "text/javascript"; js_obj.setAttribute("src",url); document.body.appendChild(js_obj); };
sc.jsp代码如下:
<%@ page language="java" contentType="application/x-javascript; charset=utf-8"%> <%@ page import="java.io.File" %> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.DriverManager" %> <%@ page import="java.sql.ResultSet" %> <%@ page import="java.sql.Statement" %> <%@ page import="java.sql.Connection" %> <%@ page import="java.sql.ResultSet" %> <%@ page import="java.sql.Statement" %> <%@ page import="javax.naming.Context" %> <%@ page import="javax.naming.InitialContext" %> <%@ page import="javax.sql.DataSource" %> <%! public static Connection getConnection() { Connection conn = null; try { Context context = new InitialContext(); DataSource datasource = (DataSource) context.lookup("java:comp/env/jdbc/mysql"); conn = datasource.getConnection(); } catch (Exception e) { e.printStackTrace(); } return conn; } private static String countbytitle(String titleurl) throws Exception{ StringBuffer data = new StringBuffer("["); //int yesnum = 25; //int nonum = 30; Connection conn = getConnection(); Statement st = conn.createStatement(); ResultSet rs = null; String sqlyes = ""; String sqlno = ""; int yesnum = 0; int nonum = 0; sqlyes = "SELECT count(*) FROM doc_solveproblem WHERE doctitle = '"+titleurl+"' AND 703solveproblem = 'yes'"; rs = st.executeQuery(sqlyes); if (rs.next()) { yesnum = rs.getInt(1); } sqlno = "SELECT count(*) FROM doc_solveproblem WHERE doctitle = '"+titleurl+"' AND 703solveproblem = 'no'"; rs = st.executeQuery(sqlno); if (rs.next()) { nonum = rs.getInt(1); } data.append("\""); data.append(yesnum + "\","); data.append("\""); data.append(nonum + "\""); st.close(); conn.close(); data.append("]"); System.out.println(yesnum); System.out.println(nonum); return data.toString(); } private static String cjkDecode(String text) throws Exception { if (text == null) { return ""; } //查找没有 "[", 直接返回. if (text.indexOf('[') == -1) { return text; } StringBuffer newTextBuf = new StringBuffer(); for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); if (ch == '[') { int rightIdx = text.indexOf(']', i + 1); if (rightIdx > i + 1) { String subText = text.substring(i + 1, rightIdx); //james:主要是考虑[CDATA[]]这样的值的出现 if (subText.length() > 0) { ch = (char) Integer.parseInt(subText, 16); } i = rightIdx; } } newTextBuf.append(ch); } return newTextBuf.toString(); } %> <% String titleurl = cjkDecode(request.getParameter("q")); String data = "[]"; try { data = countbytitle(titleurl); } catch (Exception e) { e.printStackTrace(); } response.getWriter().print("var data = " + data + ";"); response.getWriter().print("var titleurl = '" + titleurl + "';"); response.getWriter().print("test(titleurl, data);"); %>
看下你的数据库连接有没有关闭...
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。