在JSP页面中调用Spring容器注入的Bean的2种方法
2017-07-25 10:34
701 查看
方法一:
1.首先在jsp中导入:
<jsp:directive.page import="org.springframework.web.context.WebApplicationContext"/>
2.然后可以调用spring容器管理的Bean了(这里实例调用的是CalendarMapper 对象):
Jsp中调用spring管理的Bean代码如下:
WebApplicationContext context = (WebApplicationContext)this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
CalendarMapper calendarMapper = (CalendarMapper)context.getBean("calendarMapper");
方法二:
1.在jsp中导入:
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@page import="org.springframework.web.context.WebApplicationContext" %>
2.然后可以调用spring容器管理的Bean了:
WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
CalendarMapper calendarMapper = (CalendarMapper)context.getBean("calendarMapper");
1.首先在jsp中导入:
<jsp:directive.page import="org.springframework.web.context.WebApplicationContext"/>
2.然后可以调用spring容器管理的Bean了(这里实例调用的是CalendarMapper 对象):
Jsp中调用spring管理的Bean代码如下:
WebApplicationContext context = (WebApplicationContext)this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
CalendarMapper calendarMapper = (CalendarMapper)context.getBean("calendarMapper");
方法二:
1.在jsp中导入:
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils" %>
<%@page import="org.springframework.web.context.WebApplicationContext" %>
2.然后可以调用spring容器管理的Bean了:
WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
CalendarMapper calendarMapper = (CalendarMapper)context.getBean("calendarMapper");
相关文章推荐
- 在JSP页面中调用Spring容器注入的Bean的2种方法
- 在JSP页面中调用Spring容器注入的Bean的2种方法
- JSP页面中调用Spring容器注入的Bean
- 如何在JSP页面中调用Spring容器注入的Bean?
- JSP页面调用Spring容器注入的Bean
- 如何在JSP页面中调用Spring容器注入的Bean?
- jsp页面中静态方法调用使用service的类,注入静态工具类使用service
- jsp自定标签(并且注入spring容器中的bean)
- 【spring】【转】Spring 方法注入 非单例bean的调用
- SPRING中BEAN注入成功,可是启动WEB服务器,调用方法时,BEAN全是空,NullpointerException
- JSP页面怎样调用Spring配置文件中定义的Bean
- JSP 获取spring容器中bean的两种方法总结
- JSP页面调用spring容器中的对象
- 通过字符创调用接口中实现类的方法,SpringBean自动注入,
- 创建Bean的三种方式 在大多数情况下,Spring容器直接通过new关键字调用构造器来创建Bean实例,而class属性指定Bean实例的实现类,但这不是实例化Bean的唯一方法。实际上,Sprin
- main方法中调用spring注入bean
- Spring 方法注入 非单例bean的调用
- 随web容器启动Java类,调用spring容器中的的bean及其方法
- Servlet自动注入Spring容器中的Bean解决方法
- 如何让servelt和Filter注入到spring容器或者在servlet中调用spring中的bean