1.Tomcat服務器的/work 目錄的作用是:Tomcat將JSP生成的Servlet源文件和字節碼文件放到這個目錄下。
2.下載完struts2後,找到apps下的web.xml和struts.xml文件,將其拷到項目的相應位置。其中struts.xml放到src下。
3.在struts.xml配置中
<package name="example" namespace="/example" extends="struts-default">
如果缺少extends="struts-default" 將會報錯。
4.<constant name="struts.devMode" value="true" /> 修改配置文件後,不用重啓服務器,立刻生效。
5.運行原理:瀏覽器輸入http://localhost:8080/test/testPackage/hello
瀏覽器把請求發到tomcat服務器後,tomcat會看是請求哪個web application,發現是test應用後,讀取test項目的web.xml
發現web.xml裏有filter攔截器,並且會攔截所有的請求。
攔截到請求後,tomcat會去讀取web.xml的package
找到相應的package後,會查找該package下是否有請求中的action(hello)
然後找到action中的result
最後,jsp會把內容反饋給瀏覽器。
6.struts中的namespace決定了action的訪問路徑,默認爲空,表示可以接受所有路徑的action
namespace可以爲/或者/xxx或者/xxx/yy,對應的action訪問路徑爲/index.action或者/xxx/index.action或者/xxx/yy/index.action
namespace最好也用模塊名來進行。
7.當在瀏覽器裏只輸入項目,namespace爲空,在struts.xml裏找不到默認的namespace,則程序會返回到web.xml裏找<welcome-file-list>
如果沒有找到<welcome-file-list>,則報錯。
8.action默認調用execute方法,但可以通過method=""來配置其他的方法。
9.action的參數傳遞,可以在請求後面加?name=winston&age=8 來傳參數,但需要在action類中對應的有getName和setName方法,struts在找的過程中,找的是get和set的後面的內容,而不是直接操作屬性。
struts2學習筆記1
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
struts2的迭代
藍色毒箭蛙
2019-02-23 13:46:03
Struts2輸入校驗總結
5fresh
2019-02-23 00:41:21
struts2日期類型轉換
chausa
2019-02-23 00:16:04
第一個Struts2例子
夜貓子java
2019-02-23 00:07:32
FreeMarker的優點和缺點
oecp123
2019-02-23 00:00:51
struts2與ActionContext
bird_wang
2019-02-22 23:35:29
struts2標籤詳解
bird_wang
2019-02-22 23:35:28
Struts 2中實現文件下載(修正中文問題)
bird_wang
2019-02-22 23:35:25
第一次寫博客
aiyunyisheng
2019-02-22 22:59:35
org.apache.struts2.json.JSONWriter can not access a member of class
JavaLuSir
2019-02-22 22:11:55
>>> FilterDispatcher <<< is deprecated! Please use the new filters!
青澀的夢
2019-02-22 22:02:59
Struts2 訪問request、session和application對象(一)
myapple123
2019-02-22 21:51:34
Struts2錯誤1:Exception starting filter struts2
enlai1988
2019-02-22 21:47:06
struts1、 struts2所有版本jar包下載地址大全
彭票
2019-02-22 21:34:33