在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 ;

你可能感兴趣的:(spring,bean,jsp,Web)