怎么在jsp页面中调用service层中类的方法

如题所述

首先在配置文件里注明bean,如下所示:

[html] view plain copy
<beans:bean id="clientService" class="cn.bandlive.service.impl.ClientServiceImpl">
<property name="clientMapper" ref="clientDao"></property>
<property name="clientThirdplatformMapper" ref="clientThirdplatformDao"></property>
</beans:bean>

然后在jsp的<%%>中通过WebApplicationContextUtils工具类获取ApplicationContext对象,如下所示:

[html] view plain copy
ApplicationContext ctx =
WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());

ClientService clientService = (ClientService) ctx.getBean("clientService");
这样你就可以调用clientService里面的方法
温馨提示:答案为网友推荐,仅供参考
相似回答