在JSP中使用Spring其實(shí)很容易,主要用到Spring的WebApplicationContextUtils.getWebApplicationContext函數(shù)。
要再JSP里面得到ApplicationContext需要這么做.
首先
import="org.springframework.web.context.support.*,org.springframework.context.*"
然后可以通過如何做法:
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
這樣就得到了ApplicationContext,就可以操作Spring了。
JSP本來就可以認(rèn)為是一個(gè)Servlet,所以使用getServletContext()就是理所應(yīng)當(dāng)了。