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中添加:
- <listener>
- <listener-class>
- org.springframework.web.context.request.RequestContextListener
- </listener-class>
- </listener>
重新啓動,你會發現,現在錯誤沒有了。
2
之前在用struts2.0做表單提交時,爲了防止重複提交,使用了自帶的token攔截器。攔截器的配置很簡單,但是,不知道爲什麼,使用攔截器後,原本和struts綁定的bean無法完成數據的綁定,每次回action取bean中的內容均爲null,實在讓人鬱悶。
後來,發現需要再加上一個默認的攔截器
重新啓動 問題解決了