HttpSession session = request.getSession();
IUserDao ud=(IUserDao)this.getObjectFromApplication(session.getServletContext(), "IUserDao");
执行后ud即可直接调用其中的方法
/**
* 通过WebApplicationContextUtils 得到Spring容器的实例。根据bean的名称返回bean的实例。
* @param servletContext :ServletContext上下文。
* @param beanName :要取得的Spring容器中Bean的名称。
* @return 返回Bean的实例。
*/
private Object getObjectFromApplication(ServletContext servletContext,String beanName){
//通过WebApplicationContextUtils 得到Spring容器的实例。
ApplicationContext application=WebApplicationContextUtils.getWebApplicationContext(servletContext);
//返回Bean的实例。
return application.getBean(beanName);
}