资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

Convention插件-创新互联

为于都等地区用户提供了全套网页设计制作服务,及于都网站建设行业解决方案。主营业务为成都网站制作、成都做网站、外贸营销网站建设、于都网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!>考虑使用COnvention插件可以进行零配置而且插件进行很多规范的约定也可以对开发合作当中按着它相应的规律开发..感觉也挺方便管理的.下面简单介绍它的使用. 首先我们需要使用到的jar包: Java代码 struts2-convention-plugin-2.1.8.jar struts2-core-2.1.8.jar xwork-core-2.1.6.jar commons-fileupload-1.2.1.jar freemarker2.3.16.jar struts2-convention-plugin-2.1.8.jar struts2-core-2.1.8.jar xwork-core-2.1.6.jar commons-fileupload-1.2.1.jar freemarker2.3.16.jar web.xml的配置 Xml代码 struts org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts *.action struts org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts *.action struts.xml的配置 Xml代码 dojo..*,^struts..* input,back,cancel,browse true input,back,cancel,browse /html/error_page_404.html /WEB-INF/template/shop/error.ftl dojo..*,^struts..* input,back,cancel,browse true input,back,cancel,browse /html/error_page_404.html /WEB-INF/template/shop/error.ftl action的代码 我在Myeclipse新建的web项目中建立action.shop.HelloAction Java代码 public class HelloActionextends ActionSupport { public String execute() { return "test"; } public String mysql() { return "test"; } } public class HelloActionextends ActionSupport { public String execute() { return "test"; } public String mysql() { return "test"; } } 然后你在WEB-INF/template新建文件夹shop(这里新建的文件夹名字要和你建立的Action对应的存放文件夹名字符合) 然后建立文件一个jsp或者tld或者jsf文件名字为hello_test使用http://localhost:8080/web/shop/hello.action时将会直接跳到该页面进行显示加了方法的名的话访问就使用http://localhost:8080/web/shop/hello!mysql.action 下面详细解析下struts.xml中Convention配置 1.1. 设置结果页面路径 默认所有的结果页面都存储在WEB-INF/content下,你可以通过设置struts.convention.result.path这个属性的值来改变到其他路径。如: Xml代码 这样你在就必须将你需要跳转的页面放在template下面 struts2支持.jsp .html .htm .vm格式的文件。 下面是actiong和结果模版的映射关系: URL Result File that could match Result Type /hello success /WEB-INF/content/hello.jsp Dispatcher /hello success /WEB-INF/content/hello-success.htm Dispatcher /hello success /WEB-INF/content/hello.ftl FreeMarker /hello input /WEB-INF/content/hello-world-input.vm Velocity /hello error /WEB-INF/content/test/test2/hello-error.html Dispatcher 以上的内容来自struts2的文档 [url]http://struts.apache.org/2.1.6/docs/convention-plugin.html [/url] 当然,简单的通过默认的方式来进行配置不能完全满足实际项目的需要。所幸,convention的零配置是非常灵活的。 1.2. 设置Convention搜索包 默认包路径包含action,actions,struts,struts2的所有包都会被struts作为含有Action类的路径来搜索。你可以通过设置struts.convention.package.locators属性来修改这个配置。如: Xml代码 则定义了在项目中,包路径包含web和action的将被视为Action存在的路径来进行搜索。 Com.ustb.web.*/com.ustb.action.*都将被视为含有Action的包路径而被搜索。 接着,Convention从前一步找到的package以及其子package中寻找 com.opensymphony.xwork2.Action 的实现以及以Action结尾的类: com.example.actions.MainAction com.example.actions.products.Display (implements com.opensymphony.xwork2.Action) com.example.struts.company.details.ShowCompanyDetailsAction 1.3. 命名空间 命名空间。从定义的.package.locators标示开始到包结束的部分,就是命名空间。举个例子: xxx.xxx.action.shop.helloAction的命名空间是:”/shop”。 xxx.xxx.action.shop.detail.UserAction的命名空间是:”/shop/detail” 1.4. Actin类名路径分割 Convention通过如下规则确定URL的具体资源部分:去掉类名的Action部分。然后将将每个分部的首字母转为小写,用’-’分割,你可以设置struts.convention.action.name.separator 如 Xml代码
网页题目:Convention插件-创新互联
本文URL:http://cdkjz.cn/article/cogphp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220