The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the...



異常信息:The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

問題描述: 在jsp頁面中使用struts2.0標籤,訪問jsp頁面時會出現異常.

web.xml部分配置文件:

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.action</url-pattern>
  </filter-mapping>

問題原因:

如果想要在jsp文件中,採用 struts的tag,那麼jsp必須是通過action跳轉得到,也就是必須通過web.xml所配置的過濾器訪問文件,否則會有異常。
解決辦法:
方案一:將web.xml 的過濾器,從 *.action 修改爲: /* 。

方案二:web.xml 中再添加一個filter 
 <filter-mapping> 
    <filter-name>struts2</filter-name> 
    <url-pattern>*.jsp</url-pattern> 
</filter-mapping> 
<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>*.action</url-pattern>
  </filter-mapping>


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