云自无心水自闲

天平山上白云泉,云自无心水自闲。何必奔冲山下去,更添波浪向人间!
posts - 288, comments - 524, trackbacks - 0, articles - 6
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

struts2中的conventions插件

Posted on 2009-08-24 14:25 云自无心水自闲 阅读(560) 评论(0)  编辑  收藏 所属分类: Java心得体会Struts2
struts2中conventions plugin的url取名规则:
假设有一个类:com.example.actions.HelloWorld,
Struts2会自动搜索所有实现了com.opensymphony.xwork2.Action接口或者在struts.xml中<constant name="struts.convention.package.locators" value="actions"/> 指定的包下的类。
现存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";
}


只有注册用户登录后才能发表评论。


网站导航: