注解实现struts2零配置
零配置指的是不经过配置文件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零配置的更多相关文章
- Struts2 Convention Plugin ( struts2 零配置 )
Struts2 Convention Plugin ( struts2 零配置 ) convention-plugin 可以用来实现 struts2 的零配置.零配置的意思并不是说没有配置,而是通过约 ...
- 菜鸟学Struts2——零配置(Convention )
又是周末,继续Struts2的学习,之前学习了,Struts的原理,Actions以及Results,今天对对Struts的Convention Plugin进行学习,如下图: Struts Conv ...
- spring+hibernate+struts2零配置整合
说句实话,很久都没使用SSH开发项目了,但是出于各种原因,再次记录一下整合方式,纯注解零配置. 一.前期准备工作 gradle配置文件: group 'com.bdqn.lyrk.ssh.study' ...
- Struts2零配置介绍(约定访问)
从struts2.1开始,struts2 引入了Convention插件来支持零配置,使用约定无需struts.xml或者Annotation配置 需要 如下四个JAR包 插件会自动搜索如下类 act ...
- struts2 零配置
一.新建一个web项目,命名为:struts2 二.导入strut2所需的jar包 所需jar下载:http://pan.baidu.com/s/1dDxP4Z3 三.配置struts2的启动文件,在 ...
- struts2零配置參考演示样例
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2 ...
- struts2 Convention插件零配置,使用注解开发
从struts21开始,struts2不再推荐使用codebehind作为零配置插件,而是改用Convention插件来支持零配置.与以前相比较,Convention插件更彻底. 使用Conventi ...
- Struts2 注解零配置方法(convention插件使用)
最近接触到一个新的项目,是做一个使用S2SH的电子商务商城的二次开发.之前使用过S2SH,在此之前的项目中,Struts2 使用的是XML配置而这个项目是使用注解.在这个项目中,注解还不需要使用Act ...
- struts2 convention-plugin实现零配置
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少.使得Action等配置不必写在Struts.xml中. convention-plugin的约定 1. ...
随机推荐
- jquery 浏览器打印
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- mybatis的注解开发之三种动态sql
脚本sql XML配置方式的动态SQL我就不讲了,有兴趣可以自己了解,下面是用<script>的方式把它照搬过来,用注解来实现.适用于xml配置转换到注解配置 @Select(" ...
- The way to Go(2): 语言的主要特性与发展的环境和影响因素
Reference: Github: Go Github: The way to Go 语言的主要特性与发展的环境和影响因素 现有编程语言对于Go语言发展的影响: Why Go? C/C++ 的发展速 ...
- UVa 1451 平均值
https://vjudge.net/problem/UVA-1451 题意:给定长度为n的01串,选一个长度至少为L的连续子串,使得子串中数字的平均值最大. 思路:这题需要数形结合,真的是很灵活. ...
- windows 模拟用户会话创建进程
在渗透当中,经常会碰到这样的问题.一个机器,机器上好几个用户,或者域内,想让某个机器的某个会话执行你想要执行的程序,或者中马,以当前会话来上线. 现在模拟如下的一个情况: 严格的DMZ,内网--> ...
- Yandex.Algorithm 2011 Round 2 D. Powerful array 莫队
题目链接:点击传送 D. Powerful array time limit per test 5 seconds memory limit per test 256 megabytes input ...
- PCH Warning: header stop cannot be in a macro or #if block.
在编写头文件时,遇到这么一个warning:PCH Warning: header stop cannot be in a macro or #if block. An intellisense PC ...
- c++ 满足条件拷贝,容器扩容(copy_if)
#include <iostream> // cout #include <algorithm> // copy_if, distance #include <vecto ...
- 用java代码将数组元素顺序颠倒
package test; public class Recover { public int[] reverse(int[] a) { int[] b = new int[a.length]; in ...
- MongoDB(课时12 字段判断)
3.4.2.7 判断某个字段是否存在 使用“$exists”可以判断某个字段是否存在,如果设置为true表示存在,false表示不存在. 范例:查询具有parents成员的数据 db.students ...