当前位置:
首页 >
前端技术
> javascript
>内容正文
javascript
JSP页面中调用Spring Bean
生活随笔
收集整理的这篇文章主要介绍了
JSP页面中调用Spring Bean
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
前言
- spring boot 2.0.3.RELEASE
- spring mvc view : jsp
JSP页面中调用Spring Bean
在 JSP 页面获得 WebApplicationContext
方法1
<%@page import="org.springframework.web.context.WebApplicationContext" %> <%@page import="org.springframework.web.context.support.WebApplicationContextUtils" %> ... WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); ...方法2
<%@page import="org.springframework.web.context.WebApplicationContext" %> ... WebApplicationContext context = (WebApplicationContext)this.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); ...示例
<%@page import="org.springframework.web.context.WebApplicationContext" %> <%@page import="org.springframework.web.context.support.WebApplicationContextUtils" %> <%@page import="my.package.service.IArticleService" %> ... WebApplicationContext context=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext()); IArticleService articleService= (IArticleService)context.getBean("articleService"); ...参考
https://docs.spring.io/spring-framework/docs/5.0.6.RELEASE/spring-framework-reference/web.html#web-integration-common
总结
以上是生活随笔为你收集整理的JSP页面中调用Spring Bean的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 吃中药输卵管居然通了是怎么回事
- 下一篇: javascript Window 对象