Spring环境下,JSP中直接调用bean,而不需要对spring进行重新初始化

//首先初始化Spring上下文
 WebApplicationContext springContext = (WebApplicationContext) getServletContext()
   .getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
 //获取数据访问对象
 JdbcTemplate jdbcTemplate = (JdbcTemplate)springContext.getBean("jdbcTemplate");

你可能感兴趣的:(spring)