天天看點

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>  
<listener>
		<listener-class>
			org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>      

重新啟動,你會發現,現在錯誤沒有了。

2

之前在用struts2.0做表單送出時,為了防止重複送出,使用了自帶的token攔截器。攔截器的配置很簡單,但是,不知道為什麼,使用攔截器後,原本和struts綁定的bean無法完成資料的綁定,每次回action取bean中的内容均為null,實在讓人郁悶。 

後來,發現需要再加上一個預設的攔截器

重新啟動 問題解決了

繼續閱讀