在Spring+Struts的项目中,Spring和struts可以和Servlet进行耦合。
但在非Action的类中,如果实现了Struts2的ServletContextAware接口,则调用
时会出现取不到值的情况,报空指针错误。如果实现的是Spring3提供的ServletContextAware接口,则一切正常。
附:从Spring的Bean中获取servletcontext 和 applicationContext
[url]http://hjy2099.iteye.com/blog/290591[/url]
但在非Action的类中,如果实现了Struts2的ServletContextAware接口,则调用
String filepath = servletContext.getRealPath("/"); 时会出现取不到值的情况,报空指针错误。如果实现的是Spring3提供的ServletContextAware接口,则一切正常。
附:从Spring的Bean中获取servletcontext 和 applicationContext
[url]http://hjy2099.iteye.com/blog/290591[/url]
本文探讨了在Spring+Struts项目的非Action类中实现Struts2的ServletContextAware接口时遇到的问题,即无法通过servletContext获取真实路径并抛出空指针异常。文章指出若改为使用Spring3提供的同名接口则能正常工作。
3348

被折叠的 条评论
为什么被折叠?



