注解实现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. ...
随机推荐
- SxsTrace
https://troubleshooter.xyz/wiki/fix-the-application-has-failed-to-start-because-the-side-by-side-con ...
- BZOJ2724 [Violet]蒲公英 分块
题目描述 经典区间众数题目 然而是权限题,所以题目链接放Luogu的 题解 因为太菜所以只会$O(n*\sqrt{n}+n*\sqrt{n}*log(n))$的做法 就是那种要用二分的,并不会clj那 ...
- 4、CommonChunkPlugin提取公共js-提取多个
cnpm install css-loader --save-dev //css-loader 是将css打包进js cnpm install style-loader --save-dev ...
- Springboot 学习笔记 之 Day 1
SpringBoot快速入门 https://spring.io/ 1. SpringBoot简介Spring Boot来简化Spring应用开发,约定大于配置,去繁从简,just run就能创建一个 ...
- Python day16 tag式整体退出技巧
在写一些服务器时,往往会多层嵌套循环,可利用tag变量实现整体退出功能,代码: tag=True while tag: print('level1') choice=input('level1> ...
- [调试][程序打印]当printf不能用时,使用C++的不定参数来搞定OutputDebugString打印
void _trace( char* str , ...) //类似printf{ va_list vlist; va_start(vlist , str ); char a [100] ; vspr ...
- 【Jmeter】Jmeter 5.0新特性
前言 Jmeter 5.0这次的核心改进是在许多地方改进了对 Rest 的支持,此外还有调试功能.录制功能的增强.报告的改进等. 我也是因为迁移到了Mac,准备在Mac上安装Jmeter的时候发现它已 ...
- Codeforces 899E - Segments Removal
899E - Segments Removal 思路:priority_queue+pair 代码: #include<bits/stdc++.h> using namespace std ...
- socket+django
1.socket 网络上任意两个程序之间要进行通信,需要依靠socket(端口).socket封装了TCP/IP协议,让网络通信基于TCP/IP协议的形式实现. socket可以翻译为插座,那么一个服 ...
- 《图解Http》 HTTPS 安全协议
相关博客:https://www.cnblogs.com/chentianwei/p/9374341.html (讲的更明白,有图) HTTPS 7.1http的缺点 使用明文,内容会被窃听. 不验 ...