1. 程式人生 > >struts2註解&struts404錯誤---【小白系列】0基礎到熟練應用struts2框架(七)

struts2註解&struts404錯誤---【小白系列】0基礎到熟練應用struts2框架(七)

註解就是對xml的代替,採用註解的方式會加快開發速度。但是在實際開發中我們使用註解+xml的方式,因為xml中有些東西,註解無法替代。

註解開發一共分為兩步

1.匯入jar包

匯入struts-convention-plugin.jar


2.配置action

配置照著struts.xml配置就好了

注意

因為我們載入了外掛包,struts載入配置檔案時就會變成 1.載入default.properties 2. 載入struts-default.xml 3.載入struts-plugin.xml 4.載入struts.xml 5. 載入struts.proprties 6.載入 web.xml
在載入struts-plugin.xml時,裡面有一句

<constantname="struts.convention.package.locators"value="action,actions,struts,struts2"/>

這是配置sturts掃描action的,只有在上面那四個包中的action才會被掃描到,如果你的action沒寫在上述四個包中,你需要改包,或者copy這個配置程式碼在struts.xml中寫上

<constant name="struts.convention.package.locators" value="action,actions,struts,struts2,你的包名"/>

這樣struts就會掃描你的包了。

以上是解決找不到action或者執行直接報404錯誤。