servlet 和 struts2 同时使用 以及 使用struts2标签库时报错
生活随笔
收集整理的這篇文章主要介紹了
servlet 和 struts2 同时使用 以及 使用struts2标签库时报错
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
做網(wǎng)頁(yè)的時(shí)候 想讓 servlet 和 struts 都有效。 但是在過濾的時(shí)候出了點(diǎn)問題: 就是 過濾器的*.action 的時(shí)候 struts 標(biāo)簽庫(kù)失效的問題
我覺得以下是個(gè)不錯(cuò)的 解決方案:
轉(zhuǎn)載:http://blog.sina.cn/dpool/blog/s/blog_7d681d490100zbwf.html
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. - [unknown location]
這是使用struts2最常見的一個(gè)錯(cuò)誤
經(jīng)過測(cè)試得知,我們?cè)趈sp頁(yè)面使用struts-tag這個(gè)標(biāo)簽庫(kù)時(shí), 我們必須要先過action才能正確使用,不然便會(huì)報(bào)錯(cuò)! 報(bào)的就是上面的錯(cuò)誤,說的是struts-tags這個(gè)標(biāo)簽庫(kù)必須在request被通過的時(shí)候才能使用, 我們需要為struts的標(biāo)簽初始化,而要初始化的前提就是進(jìn)入action!
所以我得到, 在我們先進(jìn)入action后在跳轉(zhuǎn)到j(luò)sp頁(yè)面, 在jsp頁(yè)面使用struts2標(biāo)簽時(shí)不會(huì)出錯(cuò),但是如果我們直接進(jìn)入jsp頁(yè)面便會(huì)出錯(cuò)誤!
有些人可能沒有遇到,那是因?yàn)槟阍趧?chuàng)建struts2的項(xiàng)目時(shí)選擇的是/×,而不是*.do或者是*.action。
如果你是*.do或者*.action 的方式創(chuàng)建的項(xiàng)目,那你要這樣錯(cuò)處理才不會(huì)出錯(cuò)誤,當(dāng)然這只是其中的一種方式:
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
<!-- 記住加入這個(gè)配置,不然在使用struts-tag標(biāo)簽會(huì)報(bào)錯(cuò)誤 -->
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
也就是在web.xml中為struts2的的filter-mapping添加一個(gè),把jsp放行,不攔截jsp
等于是你訪問jsp等于是進(jìn)來action,所以這樣等于是為struts2-tag標(biāo)簽初始化,
你再去使用就不會(huì)出錯(cuò)誤了!
如果你是直接建的是/*這種struts2的項(xiàng)目就不需要做這一步驟!
我覺得以下是個(gè)不錯(cuò)的 解決方案:
轉(zhuǎn)載:http://blog.sina.cn/dpool/blog/s/blog_7d681d490100zbwf.html
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. - [unknown location]
這是使用struts2最常見的一個(gè)錯(cuò)誤
經(jīng)過測(cè)試得知,我們?cè)趈sp頁(yè)面使用struts-tag這個(gè)標(biāo)簽庫(kù)時(shí), 我們必須要先過action才能正確使用,不然便會(huì)報(bào)錯(cuò)! 報(bào)的就是上面的錯(cuò)誤,說的是struts-tags這個(gè)標(biāo)簽庫(kù)必須在request被通過的時(shí)候才能使用, 我們需要為struts的標(biāo)簽初始化,而要初始化的前提就是進(jìn)入action!
所以我得到, 在我們先進(jìn)入action后在跳轉(zhuǎn)到j(luò)sp頁(yè)面, 在jsp頁(yè)面使用struts2標(biāo)簽時(shí)不會(huì)出錯(cuò),但是如果我們直接進(jìn)入jsp頁(yè)面便會(huì)出錯(cuò)誤!
有些人可能沒有遇到,那是因?yàn)槟阍趧?chuàng)建struts2的項(xiàng)目時(shí)選擇的是/×,而不是*.do或者是*.action。
如果你是*.do或者*.action 的方式創(chuàng)建的項(xiàng)目,那你要這樣錯(cuò)處理才不會(huì)出錯(cuò)誤,當(dāng)然這只是其中的一種方式:
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping>
<!-- 記住加入這個(gè)配置,不然在使用struts-tag標(biāo)簽會(huì)報(bào)錯(cuò)誤 -->
<filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
也就是在web.xml中為struts2的的filter-mapping添加一個(gè),把jsp放行,不攔截jsp
等于是你訪問jsp等于是進(jìn)來action,所以這樣等于是為struts2-tag標(biāo)簽初始化,
你再去使用就不會(huì)出錯(cuò)誤了!
如果你是直接建的是/*這種struts2的項(xiàng)目就不需要做這一步驟!
總結(jié)
以上是生活随笔為你收集整理的servlet 和 struts2 同时使用 以及 使用struts2标签库时报错的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C# 读取照片的EXIF信息
- 下一篇: oracle怎样修改表名、列名、字段类型