零配置指的是不经过配置文件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. 【第二十七章】 springboot + zipkin(brave-okhttp实现)

    本文截取自:http://blog.csdn.net/liaokailin/article/details/52077620 一.前提 1.zipkin基本知识:附8 zipkin 2.启动zipki ...

  2. 【第十六章】 springboot + OKhttp + String.format

    模拟浏览器向服务器发送请求四种方式: jdk原生的Http包下的一些类 httpclient(比较原始,不怎么用了):第一章 HttpClient的使用 Okhttp(好用,推荐) retrofit( ...

  3. Redis Cluster集群

    一.redis-cluster设计 Redis集群搭建的方式有多种,例如使用zookeeper等,但从redis 3.0之后版本支持redis-cluster集群,Redis-Cluster采用无中心 ...

  4. 正则表达式及R字符串处理之终结版

    http://yphuang.github.io/blog/2016/03/15/regular-expression-and-strings-processing-in-R/ 0.动机:为什么学习字 ...

  5. 怎样借助Python爬虫给宝宝起个好名字--python 学习

    每个人一生中都会遇到一件事情,在事情出现之前不会关心,但是事情一旦来临就发现它极其重要,并且需要在很短的时间内做出重大决定,那就是给自己的新生宝宝起个名字. 因为要在孩子出生后两周内起个名字(需要办理 ...

  6. Codeforces Round #303 (Div. 2)E. Paths and Trees 最短路

    E. Paths and Trees time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  7. mysql 问题 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdb

    异常错误:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.c ...

  8. English trip -- VC(情景课)9 B Outside chores 室外家务

    Vocabulary focus 核心词汇 cutting the grass 修剪草坪 getting the mail  收到邮件 taking out the trash  把垃圾带出去 wal ...

  9. codeforces 536a//Tavas and Karafs// Codeforces Round #299(Div. 1)

    题意:一个等差数列,首项为a,公差为b,无限长.操作cz是区间里选择最多m个不同的非0元素减1,最多操作t次,现给出区间左端ll,在t次操作能使区间全为0的情况下,问右端最大为多少. 这么一个简单题吞 ...

  10. php--------删除数组的第一个元素和最后一个元素

    对于一个php数组,该如何删除该数组的第一个元素或者最后一个元素呢?其实这两个过程都可以通过php自带的函数 array_pop 和 array_shift 来完成,下面就具体介绍一下如何来操作. ( ...