struts2 spring issue list

1、关于调用struts的action时出现如下错误:
No thread-bound request found: Are you referring to request attributes outside of an actual web request? If you are actually operating within a web request and still receive this message,your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, useRequestContextListeneror RequestContextFilter to expose the current request.
必然,这个错误是由于IOC引起的,如果不用IOC的方式,这个错误就不会出现。一种出现该错误的情况在于你的Action配置了 session,request或则response。大家都知道在struts2中,request和response的实现机制已经大不一样了,不以参数的形式存在于方式之中,而是通过实现SessionAware, ServletRequestAware,ServletResponseAware接口的set方法实现的
不管怎么样,解决办法是有的,其实该错误本身就说了解决办法(useRequestContextListeneror RequestContextFilter to expose the current request):
在web.xml中添加:

Xml代码 
  1. <listener>  
  2.     <listener-class>  
  3.         org.springframework.web.context.request.RequestContextListener  
  4.     </listener-class>  
  5. </listener>  


重新启动,你会发现,现在错误没有了。

 

 

2

之前在用struts2.0做表单提交时,为了防止重复提交,使用了自带的token拦截器。拦截器的配置很简单,但是,不知道为什么,使用拦截器后,原本和struts绑定的bean无法完成数据的绑定,每次回action取bean中的内容均为null,实在让人郁闷。 

后来,发现需要再加上一个默认的拦截器

重新启动 问题解决了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章