Skip to content

Instantly share code, notes, and snippets.

@nileshk
Created October 7, 2013 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nileshk/6872654 to your computer and use it in GitHub Desktop.
Save nileshk/6872654 to your computer and use it in GitHub Desktop.
JSP page to retrieve DataSource (Apache DBCP in this example) from Spring context and display status information for the database connection pool. Meant as a general example for how to access the Spring context from JSP pages (e.g. could be useful in debugging a running application in production where you could drop in JSP pages to evaluate thin…
<!DOCTYPE html>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.apache.commons.dbcp.BasicDataSource" %>
<%
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
BasicDataSource dataSource = (BasicDataSource) context.getBean("dataSource");
%>
<html>
<head>
<title>Status</title>
</head>
<body>
<h2>DataSource Settings</h2>
JDBC URL: <%= dataSource.getUrl() %><br />
JDBC User: <%= dataSource.getUsername() %><br />
Pool initial size: <%= dataSource.getInitialSize() %><br />
Pool max active: <%= dataSource.getMaxActive() %><br />
Number of active connections: <%= dataSource.getNumActive() %><br />
Number of idle connections: <%= dataSource.getNumIdle() %><br />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment