Welcome

首页 / 网页编程 / JSP / 在JSP中使用Spring

在JSP中使用Spring2011-02-11在JSP中使用Spring其实很容易,主要用到Spring的WebApplicationContextUtils.getWebApplicationContext函数。

要再JSP里面得到ApplicationContext需要这么做.

首先

import="org.springframework.web.context.support.*,org.springframework.context.*"

然后可以通过如何做法:

ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext());

这样就得到了ApplicationContext,就可以操作Spring了。

JSP本来就可以认为是一个Servlet,所以使用getServletContext()就是理所应当了。