比如一个test.jsp页面,用户直接请求该页面,
需要在该页面中获取到spring的service.xml中
定义的bean,该如何做呢?
不能在页面中用new ClassPathXmlApplicationContext()的方法,因为这会导致
bean被重复初始化,是不是有方法可以直接从session中获得service。xml文件呢。
[b]问题补充:[/b]
我的写的 :evil:
<%
ApplicationContext ctx=WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
IpolicemanJqServie jqs=(IpolicemanJqServie)ctx.getBean("jq.jqService");
System.out.print("jqs==ddd"+jqs.getjqSituation("8a89db6023034df00123081efd171903"));
%>
这样就行了恩,谢谢
servlet中的用法
[code="java"]
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
Bean bean = (Bean) context.getBean("bean");
[/code]
翻译成jsp代码