您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> jsp编程 >> 正文

JSP 获取Spring 注入对象示例

作者:佚名    责任编辑:admin    更新时间:2022-06-22

 这篇文章主要介绍了JSP如何获取Spring 注入对象,实现代码如下,需要的朋友不要错过

     
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.context.ApplicationContext"%>

ServletContext sc = this.getServletConfig().getServletContext();
ApplicationContext ac2 = WebApplicationContextUtils.getWebApplicationContext(sc);

要获取的对象 serv = (要获取的对象) ac2.getBean("spring配置文件中的id");