struts2学习笔记之十二:struts2对异常的自动处理
package com.djoker.struts2; import java.util.Date; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.Action; public class UserAction { private String username; private String password; private Date createDate; public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public Date getCreateDate() {
return createDate;
} public void setCreateDate(Date createDate) {
this.createDate = createDate;
} public String addUser() throws Exception {
if("admin".equals(username)){
throw new UserNotFoundException("账号没有找到");
}
ServletActionContext.getRequest().setAttribute("username", username);
ServletActionContext.getRequest().setAttribute("password", password);
ServletActionContext.getRequest().setAttribute("createDate", createDate);
return Action.SUCCESS;
}
}
package com.djoker.struts2; public class UserNotFoundException extends RuntimeException { public UserNotFoundException() {
super();
// TODO Auto-generated constructor stub
} public UserNotFoundException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
} public UserNotFoundException(String message) {
super(message);
// TODO Auto-generated constructor stub
} public UserNotFoundException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
} }
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd"> <struts>
<package name="user" extends="struts-default" namespace="/user">
<global-exception-mappings>
<exception-mapping result="error" exception="com.djoker.struts2.UserNotFoundException"></exception-mapping>
</global-exception-mappings>
<action name="*User" class="com.djoker.struts2.UserAction" method="{1}User">
<exception-mapping result="error" exception="com.djoker.struts2.UserNotFoundException"></exception-mapping>
<result>/success.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>
<%@ page language="java" contentType="text/html; charset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<h1>登录失败</h1>
<!-- 获取异常信息 -->
${exception.message }<br>
<!-- 获取异常堆栈信息 -->
${exceptionStack }<br>
</body>
</html>
struts2学习笔记之十二:struts2对异常的自动处理的更多相关文章
- VSTO 学习笔记(十二)自定义公式与Ribbon
原文:VSTO 学习笔记(十二)自定义公式与Ribbon 这几天工作中在开发一个Excel插件,包含自定义公式,根据条件从数据库中查询结果.这次我们来做一个简单的测试,达到类似的目的. 即在Excel ...
- 汇编入门学习笔记 (十二)—— int指令、port
疯狂的暑假学习之 汇编入门学习笔记 (十二)-- int指令.port 參考: <汇编语言> 王爽 第13.14章 一.int指令 1. int指令引发的中断 int n指令,相当于引 ...
- Binder学习笔记(十二)—— binder_transaction(...)都干了什么?
binder_open(...)都干了什么? 在回答binder_transaction(...)之前,还有一些基础设施要去探究,比如binder_open(...),binder_mmap(...) ...
- struts2学习笔记之十:文件上传
Struts2的上传 1.Struts2默认采用了apache commons-fileupload 2.Struts2支持三种类型的上传组件 3.需要引入commons-fileupload相关依赖 ...
- java之jvm学习笔记六-十二(实践写自己的安全管理器)(jar包的代码认证和签名) (实践对jar包的代码签名) (策略文件)(策略和保护域) (访问控制器) (访问控制器的栈校验机制) (jvm基本结构)
java之jvm学习笔记六(实践写自己的安全管理器) 安全管理器SecurityManager里设计的内容实在是非常的庞大,它的核心方法就是checkPerssiom这个方法里又调用 AccessCo ...
- Android学习笔记(十二)——实战:制作一个聊天界面
//此系列博文是<第一行Android代码>的学习笔记,如有错漏,欢迎指正! 运用简单的布局知识,我们可以来尝试制作一个聊天界面. 一.制作 Nine-Patch 图片 : Nine-Pa ...
- MySQL数据库学习笔记(十二)----开源工具DbUtils的使用(数据库的增删改查)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- struts2学习笔记(一)—— struts2介绍及入门程序
一.struts2概述 1.1 什么是struts2? 在介绍Struts2之前,先来认识一下Struts1.Struts1是最早的基于MVC模式的轻量级web框架,他能够合理的划分代码结构,并包含了 ...
- Dynamic CRM 2013学习笔记(十二)实现子表合计(汇总,求和)功能的通用插件
上一篇 Dynamic CRM 2013学习笔记(十一)利用Javascript实现子表合计(汇总,求和)功能 , 介绍了如何用js来实现子表合计功能,这种方法要求在各个表单上添加js方法,如果有很多 ...
随机推荐
- tomcat的CATALINA_HOME可以不用设置
不配置tomcat的环境变量也是可以运行的 用记事本打开tomcat/bin目录下面的startup.bat 在文本的前一部分有下面的脚本代码 rem Guess CATALINA_HOME if n ...
- ubuntu 终端设置(颜色与长路径)
Linux给人最大的享受就是可以根据个人喜好去定制令自己舒服的系统配置,像终端颜色的设置就是一个典型的例子. 图1 系统默认状态下的终端显示 在没有经过自定义配置的终端下工作久了,难免容易疲劳 ...
- Head First 设计模式读书笔记
在网上学习了一段时间设计模式,总感觉不系统,很容易忘,最近买书,学习了<Head First设计模式>,受益匪浅,特做此记录,以便激励自己不断的向后学习. 原书JAVA版本,本次学习记录及 ...
- <转>exe & dll自我更新
exe & dll自我更新 分类: c/c++ 2008-10-16 22:07 756人阅读 评论(1) 收藏 举报 exedlldelayapi游戏 exe与dll的自我更新 在改 ...
- BOOST1.54简化编译
1.设置环境变量 BOOST_ROOT E:\Projects\00.CODE.SDK\boost_1_54_0 2.运行bootstrap.bat 3.运行: bjam install --tool ...
- php面向对象学习
近期跟着别人开发一套php程序,深感自己面向对象很白痴,于是再次巩固了一下面向对象的学习,自己整理了一下这几天面向对象的东西,给大家分享!! 面向对象的三大特性: 封装 -- 隐藏内部实现,稳定外部接 ...
- centos 安装apache 和 php5.6
centos 安装 php5.6,安装前需要先安装数据库和apache 安装 apache2.4 安装基础依赖:# yum install gcc gcc-c++ glibc glibc-devel ...
- String 归档
1.古罗马皇帝凯撒在打仗时曾经使用过以下方法加密军事情报:,请编写一个程序,使用上述算法加密或解密用户输入的英文字串要求设计思想.程序流程图.源代码.结果截图. 设计思想: 1)输入一个字符串str( ...
- 走读openwrt的shell的总结【转】
原文:http://blog.chinaunix.net/uid-26598889-id-3060543.html ". /etc/diag.sh" 就是将/etc/diag.sh ...
- python学习八皇后问题
0 # -*- coding: utf-8 -*- 1 import random #冲突检查,在定义state时,采用state来标志每个皇后的位置,其中索引用来表示横坐标,基对应的值表示纵坐标,例 ...