零配置指的是不经过配置文件struts.xml配置Action

首先:导入jar   struts2-convention-plugin-2.3.24.1.jar

package com.action;

import javax.xml.ws.Action;

import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results; import com.opensymphony.xwork2.ActionSupport;
/**
* @Namespace
* @Result
*/
@Namespace(value="/test")
@Results({
@Result(name="success",location="/success.jsp"),
@Result(name="redirect",location="/redirect.jsp",type="ServletRedrectResult.class"),
@Result(name="login",location="/login.jsp")
})
@ExceptionMappings( {
@ExceptionMapping(exception = "java.lange.RuntimeException", result = "error")
})
public class AnnotatedAction extends ActionSupport {
@Action(input="login")
public String login()throws Exception{
return SUCCESS;
}
@Action(input="add",output="/add.jsp")
public String add()throws Exception{
return "add";
} }

1) @ParentPackage 指定父包

2) @Namespace 指定命名空间

3) @Results 一组结果的数组

4) @Result(name="success",location="/msg.jsp") 一个结果的映射

5) @Action(input="login") 指定某个请求处理方法的请求URL。注意,它不能添加在Action类上,要添加到方法上。

6) @ExceptionMappings 一级声明异常的数组

7) @ExceptionMapping 映射一个声明异常

由于这种方式不是很常用,所以大家只做了解即可

注解实现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. spring+hibernate+struts2零配置整合

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

  4. Struts2零配置介绍(约定访问)

    从struts2.1开始,struts2 引入了Convention插件来支持零配置,使用约定无需struts.xml或者Annotation配置 需要 如下四个JAR包 插件会自动搜索如下类 act ...

  5. struts2 零配置

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

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

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

  7. struts2 Convention插件零配置,使用注解开发

    从struts21开始,struts2不再推荐使用codebehind作为零配置插件,而是改用Convention插件来支持零配置.与以前相比较,Convention插件更彻底. 使用Conventi ...

  8. Struts2 注解零配置方法(convention插件使用)

    最近接触到一个新的项目,是做一个使用S2SH的电子商务商城的二次开发.之前使用过S2SH,在此之前的项目中,Struts2 使用的是XML配置而这个项目是使用注解.在这个项目中,注解还不需要使用Act ...

  9. struts2 convention-plugin实现零配置

    零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少.使得Action等配置不必写在Struts.xml中. convention-plugin的约定 1. ...

随机推荐

  1. yarn虚拟cpu和虚拟内存

    虚拟cpu 虚拟的cpu代码并发数,如果一个container拥有2个vcpu,那么该container就可以真正的在同一时间运行两个线程,而不是靠切时间片而达到的逻辑并发.所以一般虚拟的cpu需要和 ...

  2. K条最短路径算法(KSP, k-shortest pathes):Yen's Algorithm

    参考: K最短路径算法之Yen's Algorithm Yen's algorithm 基于网络流量的SDN最短路径转发应用 K条最短路径算法:Yen's Algorithm 算法背景 K 最短路径问 ...

  3. 圆点博士 陀螺仪和加速度计MPU6050的单位换算方法

    圆点博士陀螺仪和加速度计MPU6050的单位换算方法 陀螺仪和加速度计MPU6050的单位换算方法 对于四轴的初学者,可能无法理解四轴源代码里面陀螺仪和加速度数据的那些数学转换方法.下面我们来具体描述 ...

  4. diff详解,读懂diff结果-转载

    阅读目录 1.概述 2.diff如何工作,如何理解diff的执行结果 3.Normal模式 4.Context模式 5.Unified模式 6.比较目录 7.一些有用的参数 回到顶部 1.概述 本文将 ...

  5. python 函数赋值

    ⾸先我们来理解下Python中的函数 def hi(name="yasoob"): return "hi " + name print(hi()) # outp ...

  6. MVC动态二级域名解析

    动态二级域名的实现: 应用场景:目前产品要实现block功能,因为工作需要实现二级域名:www.{CompanyUrl}.xxx.com 假设产品主域名入口为:www.xxx.com 公司员工管理:w ...

  7. Qt5_程序发布

    ZC: deploy ==> 部署 1.文件夹platforms 该文件夹 来自 Qt安装目录:F:\ZC_software_installDir\Qt5.3.2_vs2010\5.3\msvc ...

  8. spring boot开发 @autowired注入失败

    @autowired注入失败 会出现如下错误提示: 2018-05-28 08:39:41.857 INFO 8080 --- [ restartedMain] org.hibernate.Versi ...

  9. 记录Vmware Workstation及Centos6.8 的安装

    网上找到的一个非常详细的安装详解.个人觉得非常好.于是加保存一下.地址:http://www.mamicode.com/info-detail-1462939.html

  10. 绑定任意格式的XML文档到WPF的TreeView

    Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> ...