struts.xml
namespace
namespace="" ,處理所有不在已有的namespace中的其他action
action:
struts1 中 action 只有一個,
struts2 中 每訪問action,new一個新的對象。
path問題
struts2中如果href="***.jsp" ,則尋找的是當前action namespace下的jsp
如果href="/***.jsp",則尋找的是tomcat 目錄下的***.jsp
所以,要直接鏈接到文件,則應該如下:
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
href="<%=basePath%>***.jsp"
也可以把base設置在<head>中。
動態方法調用
1 strut2中的在配置action時候,可以在action中添加method屬性,
2 可以在訪問的url後加上!methodname,如 login!verify,這樣就能在發送login.action的時,不訪問execute,而訪問verify。(DMI)
WILDCARD通配符
如果有多個可以匹配,則優先匹配最精確的
action 接受url中的參數
在action 設置參數對應的屬性,寫set 和get方法,則struts2 自動注入參數到這兩個屬性中。