首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Struts应用convention-plugin实现零配置

2012-11-17 
Struts使用convention-plugin实现零配置最近开始关注URL Result File that could match Result Type /hell

Struts使用convention-plugin实现零配置

最近开始关注

                URL Result
                File that could match Result Type /hellosuccess/WEB-INF/content/hello.jspDispatcher/hellosuccess/WEB-INF/content/hello-success.htm Dispatcher/hellosuccess/WEB-INF/content/hello.ftl FreeMarker/hello-worldinput/WEB-INF/content/hello-world-input.vmVelocity/test1/test2/helloerror/WEB-INF/content/test/test2/hello-error.htmlDispatcher

                ?

                ?

                ?

                ?

                ?

                ?

                ?

                ?

                ?

                ?

                以上的内容来自

                    方法名 默认调用路径 默认映射路径 method1 /hello!method1.action . /WEB-INF/content/hello.jsp method2 /hello!method2.action. /WEB-INF/content/hello.jsp

                    通过@Action注释后

                    方法名 @Action注释后调用路径 @Action注释 后映射路径 method1 /action1!method1.action. /WEB-INF/content/action1.jsp method1 /user/action2!method2.action /WEB-INF/content/user/action2.jsp


                    通过@Actions注释

                                    package?com.example.actions;????import?com.opensymphony.xwork2.ActionSupport;???import?org.apache.<span?class="hilite1"><span?style="background-color:?#ffff00;">struts2</span></span>.convention.annotation.Action;??import?org.apache.<span?class="hilite1"><span?style="background-color:?#ffff00;">struts2</span></span>.convention.annotation.Actions;??import?org.apache.<span?class="hilite1"><span?style="background-color:?#ffff00;">struts2</span></span>.convention.annotation.Result;??import?org.apache.<span?class="hilite1"><span?style="background-color:?#ffff00;">struts2</span></span>.convention.annotation.Results;????public?class?HelloWorld?extends?ActionSupport?{??????@Action(value="/other/bar",results={@Result(name?=?"error",?location?=?"www.baidu.com",type="redirect")})????public?String?method1()?{??????return?“error”;????}??}??


                                  当我们调用 /hello -world !method1.action 时,返回 /WEB-INF/content/hello-error.jsp
                                  当我们调用 /other/bar!method1.action 时,返回 www.baidu.com

热点排行