struts2捕获action类异常
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<?xml version="1.0" encoding="UTF-8" ? >
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- 採用注解的方式 --> <constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.devMode" value="true" /> <package name="default" namespace="" extends="struts-default">
<!-- struts2捕获action类异常 -->
<global-results>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<action name="link" class="com.test.action.LoginAction">
<result>/result.jsp</result>
</action>
<action name="linkIOC" class="com.test.action.LoginActionIOC">
<result>/result.jsp</result>
</action>
</package> <!-- Add packages here --> </struts>
測试类
package com.test.action; import java.util.Map; import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport{ /**
*
*/
private static final long serialVersionUID = 1L; private Map request;
private Map session;
private Map application; public LoginAction()
{
System.out.println("loginaction构造函数!");
request=(Map) ActionContext.getContext().get("request");
session=ActionContext.getContext().getSession();
application=ActionContext.getContext().getApplication();
} public String execute()
{
//System.out.println(request);
//System.out.println(session);
//System.out.println(application); int i=100/0;/*这个地方会抛出异常,默认情况下struts2是不会捕获异常,直接抛出*/ request.put("msg", "欢迎你!");
return SUCCESS;
} }
输出结果
struts2捕获action类异常的更多相关文章
- Struts2 之 Action 类访问 WEB 资源
接着上次博客的内容我继续分享我所学到的知识,和自己在学习过程中所遇到问题以及解决方案.当然,如果读者发现任何问题均可以在下方评论告知我,先谢! 在 Action 中访问 WEB 资源 web 资源 所 ...
- Struts2中Action类的三种写法
一.普通的POJO类(没有继承没有实现)-基本不使用 POJO(Plain Ordinary Java Object)简单的Java对象,实际就是普通JavaBeans,是为了避免和EJB混淆所创 ...
- 3.Struts2中Action类的三种写法
一.普通的POJO类(没有继承没有实现)-基本不使用 public class DemoAction1 { public String execute(){ System.out.println(&q ...
- struts2的action类详解
Action类的书写方式 方式1
- 转载 Struts2之------Action类中的get,set方法和execute方法的使用规范和使用流程(规范是没有理由的,必须遵守!!!)
1,Action中get,set方法的使用流程? 前台form中有一个<input type="text" name="username"/> 如果 ...
- 2018.11.19 Struts2中Action类的书写方式
方式1: 方式2: 方式3
- Struts2的Action继承ActionSupport时,利用AOP来拦截Action出现NoSuchMethodException
参考:http://zhanghua.1199.blog.163.com/blog/static/46449807201111139501298/ 做项目的时候,由于要用到在Struts2的Actio ...
- Struts2中的Action类(解耦方式,耦合方式)
一.解耦方式 特点:对web资源进行了封装,便于单元测试. 实现:ActionContext和接口方式 1.ActionContext 特点:Action执行的上下文对象.保存了执行Action所需要 ...
- struts2笔记02-action和Action类
1.action action表示一个struts2的请求! 2.Action类 能够处理struts2请求的类. (1)属性的名字需要与JavaBeans属性保持一致. 属性的类型可以是任 ...
随机推荐
- input 密码框调出手机的数字键盘
对于某些密码,想要在手机上调出数字键盘,同时要隐藏文字.可结合type=tel和 text-security属性达到目的. input{ -webkit-text-security:disc; tex ...
- 一个简单的MVC框架的实现-基于注解的实现
1.@Action注解声明 package com.togogo.webtoservice.annotations; import java.lang.annotation.Documented; i ...
- ALTER TABLE SWITCH' statement failed. The table x' is partitioned while index 'x' is not partitioned.
1.L_Monitoring有这么些字段,ID,Collecttime,PlateType,PlateNO以及其他一些这段.建立这个表的时候是个非分区表,其中ID是主键,并在Collecttime,P ...
- C#利用UdpClient发送广播消息
首先写个接受消息的客户端.这里偷了点懒,new UdpClient(11000)就是用Udp方式侦听11000端口,侦听任何发送到11000端口的消息都会接收到. 代码 : ); Byte[] sen ...
- C#泛型集合之List
1.命名空间:System.Collections.Generic(程序集:mscorlib)2.描述: 1).表示可通过索引访问的对象的强类型列表:提供用于对列表进行搜索.排序和操作的方法. 2). ...
- vue新手入门——vue-cli搭建
首先说明,以下内容vue官网都有文档,如果觉得麻烦啰嗦,请移步至 安装-vue.js . 准备工作: 1.下载并安装node环境,一般情况下安装好node之后,npm也会安装好.具体安装的话,百度大概 ...
- [转载] Redis系统性介绍
转载自http://blog.nosqlfan.com/html/3139.html?ref=rediszt 虽然Redis已经很火了,相信还是有很多同学对Redis只是有所听闻或者了解并不全面,下面 ...
- maven学习之三
maven 创建工程: 1:直接命令:mvn archetype:generate -X -DgroupId=org.sselab -DartifactId=maven-for-mongodb -D ...
- ionic开发环境搭建之android及问题
1. 准备工作: a) 配置java开发环境 b) 配置安卓开发环境 注:下载android-studio后,可能会出现android一直在编译,出现这种情况,关掉你的as ,找到你的路 ...
- JavaScript学习笔记(七)——函数的定义与调用
在学习廖雪峰前辈的JavaScript教程中,遇到了一些需要注意的点,因此作为学习笔记列出来,提醒自己注意! 如果大家有需要,欢迎访问前辈的博客https://www.liaoxuefeng.com/ ...