Created
October 7, 2013 18:27
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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