JSP页面调用spring容器中的对象

来源:互联网 发布:淘宝买家皇冠号值钱吗 编辑:程序博客网 时间:2024/04/30 14:41

 

首先在jsp中导入:
<jsp:directive.page import="org.springframework.web.context.WebApplicationContext"/>

然后可以调用Spring容器管理的Bean了(这里实例调用的是Service对象):

<%  WebApplicationContext context = (WebApplicationContext)this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);  TestService service = (TestService)context.getBean("testService");  

%>  

未测试,先记录一下。

 

原创粉丝点击