日期:2014-05-16  浏览次数:20300 次

在jsp页面上,如何从spring容器中拿到一个bean
<%WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this

.getServletContext());

System.out.println("===========初始化成功=========");

worksService = (SomeServiceImpl) wac.getBean("someService");%>



spring部分代码:

String attrName=WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE;//值为:
"org.springframework.web.context.WebApplicationContext.ROOT"

Object attr = sc.getAttribute(attrName);
return (WebApplicationContext)attr ;