从struts2.1开始,struts2 引入了Convention插件来支持零配置,使用约定无需struts.xml或者Annotation配置

需要 如下四个JAR包

插件会自动搜索如下类

  action、actions、struts、struts2包下所有Java类
  所有实现了com.opensymphony.xwork2.Action的Java类
  所有类名以Action结尾的Java类
    下面类名都符合Convention插件
      cn.yzu.struts2.HelloAction
      cn.yzu.actions.books.BookSearchAction
      cn.yzu.struts.user.UserAction
      cn.yzu.estore.action.test.LoginAction

struts2-convention-plugin-2.3.7.jar 中struts-plugin.xml重要常量

<constant name="struts.convention.package.locators" value="action,actions,struts,struts2"/> 默认扫描包
<constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*"/> 不扫描
<constant name="struts.convention.action.suffix" value="Action"/> 默认扫描以Action结尾的类
<constant name="struts.convention.result.path" value="/WEB-INF/content/"/> 结果result页面存放位置
<constant name="struts.convention.classes.reload" value="false" /> Action类文件重新自动加载

Action映射

  如果Action类名包含Action后缀,将Action后缀去掉,将Action类名的驼峰写法,转成中划线写法
  例如:
     cn.yzu.struts2.HelloAction 映射到 /hello.action
     cn.yzu.actions.books.BookSearchAction 映射到 /books/book-search.action
     cn.yzu.struts.user.UserAction 映射到 /user/user.action
     cn.yzu.estore.action.test.LoginAction 映射到 /test/login.action

默认情况下,Convention总会到Web应用的WEB-INF/content路径下定位结果资源
  <constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
  约定: actionName + resultCode + suffix (后缀
  例如:
    访问cn.itcast.struts.user.UserAction返回success
    Convention优先使用 WEB-INF/content/user/user-success.jsp
    如果user-success.jsp不存在,会使用user-success.html
    如果user-success.html不存在,会使用user.jsp

 示例结构:

Struts2零配置介绍(约定访问)的更多相关文章

  1. Struts2 Convention Plugin ( struts2 零配置 )

    Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...

  2. 菜鸟学Struts2——零配置(Convention )

    又是周末,继续Struts2的学习,之前学习了,Struts的原理,Actions以及Results,今天对对Struts的Convention Plugin进行学习,如下图: Struts Conv ...

  3. struts2 零配置

    一.新建一个web项目,命名为:struts2 二.导入strut2所需的jar包 所需jar下载:http://pan.baidu.com/s/1dDxP4Z3 三.配置struts2的启动文件,在 ...

  4. spring+hibernate+struts2零配置整合

    说句实话,很久都没使用SSH开发项目了,但是出于各种原因,再次记录一下整合方式,纯注解零配置. 一.前期准备工作 gradle配置文件: group 'com.bdqn.lyrk.ssh.study' ...

  5. 注解实现struts2零配置

    零配置指的是不经过配置文件struts.xml配置Action 首先:导入jar   struts2-convention-plugin-2.3.24.1.jar package com.action ...

  6. struts2零配置參考演示样例

    <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2 ...

  7. struts2 正确配置通配符方式访问,报错解决

    今天遇到正确配置通配符访问action的方法,但是还是报错,原因struts 2.3 以后会内部会验证是否允许该方法,而我用的刚好是2.5的版本 要action配置中加上<allowed-met ...

  8. Struts2的零配置和rest插件

    1. 零配置使用struts2-convention-plugin-2.3.16.jar,rest使用struts2-rest-plugin-2.3.16.jar 1.1 Struts2的conven ...

  9. 从struts2.1开始Convention零配置

    从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该 ...

随机推荐

  1. Windows下配置Java开发环境

    学习Java第一步是配置本地开发环境,学习最基本的桌面开发,下面以win7为例配置Java开发环境,即:JDK+JRE+Eclipse,安装JDK的时候会默认安装JRE,根据提示安装就可以了. 首先去 ...

  2. webpack学习笔记一

    主要参考: https://blog.madewithlove.be/post/webpack-your-bags/ 起因: 作为运维狗, 对前端一窍不通但心向往之, 最近做一个Dashboard, ...

  3. salt安装与简单使用---基于centos6.5

    1.简介SaltStack 是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,一般可以理解为简化版的puppet和加强版的func.SaltStack 基于Python语言实现, ...

  4. php 获取IP

    <?php echo 'your ip is :'; if (@$_SERVER["HTTP_X_FORWARDED_FOR"]) $ip = $_SERVER[" ...

  5. Cuckoo for Hashing_双哈希表

    问题 B: Cuckoo for Hashing 时间限制: 1 Sec  内存限制: 64 MB提交: 24  解决: 12[提交][状态][讨论版] 题目描述 An integer hash ta ...

  6. 【leetcode】Minimum Depth of Binary Tree (easy)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  7. LeetCode 231 Power of Two

    Problem: Given an integer, write a function to determine if it is a power of two. Summary: 判断一个数n是不是 ...

  8. 关于 UICollectionViewCell 的一些陷阱

    如果直接使用 UICollectionViewCell 的自带属性 selected 来自定义一些样式,如: - (void)setSelected:(BOOL)selected { [super s ...

  9. valgrind检查C++内存泄漏

    valgrind --tool=memcheck --leak-check=full ./httptest Valgrind 使用 用法: valgrind [options] prog-and-ar ...

  10. Linux安装mysql最新版本纪要

    http://blog.csdn.net/frt007/article/details/50184143 http://blog.csdn.net/wb96a1007/article/details/ ...