struts2中的conventions插件
Posted on 2009-08-24 14:25 云自無心水自閑 閱讀(578) 評論(0) 編輯 收藏 所屬分類: Java 、心得體會 、Struts2struts2中conventions plugin的url取名規(guī)則:
假設有一個類:com.example.actions.HelloWorld,
Struts2會自動搜索所有實現(xiàn)了com.opensymphony.xwork2.Action接口或者在struts.xml中<constant name="struts.convention.package.locators" value="actions"/> 指定的包下的類。
現(xiàn)存HelloWorld只是一個POJO,但是他在actions包下,這樣Struts2就認可這是一個Action.
那么URL會是什么呢?是hello-world,類似于:http://localhost:8080/<contextPath>/hello-world.action.
如果你不喜歡這樣的自動分配的URL,那么可以在里面的方法使用@Action來改變
@Action("/helloWorld")
public void execute() throws Exception {
return "success";
}
假設有一個類:com.example.actions.HelloWorld,
Struts2會自動搜索所有實現(xiàn)了com.opensymphony.xwork2.Action接口或者在struts.xml中<constant name="struts.convention.package.locators" value="actions"/> 指定的包下的類。
現(xiàn)存HelloWorld只是一個POJO,但是他在actions包下,這樣Struts2就認可這是一個Action.
那么URL會是什么呢?是hello-world,類似于:http://localhost:8080/<contextPath>/hello-world.action.
如果你不喜歡這樣的自動分配的URL,那么可以在里面的方法使用@Action來改變
@Action("/helloWorld")
public void execute() throws Exception {
return "success";
}