SSH-Struts第一弹:ActionSupport类
Action继承了com.opensymphony.xwork2.ActionSupport。
- package com.candy.login;
- import com.opensymphony.xwork2.ActionSupport;
- public class LoginAction extends ActionSupport {}
继承了ActionSupport后,可以在execute()里加入以下验证信息:
- addActionError(""); // Action错误提示
- addFieldError("", ""); // 字段错误提示
- addActionMessage(""); // 错误消息
就目前继承ActionSupport的作用有两个:
1、addActionError("")/addFieldError("","")/addActionMessage("")三个方法都是从这个类继承的,可以在自己的Action中使用。
2、我找到的ActionSupport的五个静态常量,也可以在自己的Action中的使用。同时,在struts.xml中<result>/main.jsp</result>和<result name="success">/main.jsp</result>的功能是一致的。
- public static final java.lang.String SUCCESS = "success";
- public static final java.lang.String NONE = "none";
- public static final java.lang.String ERROR = "error";
- public static final java.lang.String INPUT = "input";
- public static final java.lang.String LOGIN = "login";
同时,发下web.xml和struts.xml
web.xml:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <display-name>Struts</display-name>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
struts.xml:
- <?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">
- <!-- <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache
- Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> -->
- <struts>
- <constant name="struts.i18n.encoding" value="UTF-8"></constant>
- <package name="struts2" extends="struts-default" namespace="/">
- <global-results>
- <result name="errorPath" type="redirect">
- /errorPage.jsp
- </result>
- </global-results>
- <action name="LoginAction" class="com.candy.login.LoginAction">
- <result name="error">index.jsp</result>
- <result>/WEB-INF/main.jsp</result>
- </action>
- </package>
- <!-- 引用其他模块的Struts.xml配置文件 -->
- <!-- <include file="testStruts.xml"/> -->
- <!-- Apache Struts2官方网站 -->
- <!-- http://struts.apache.org/release/2.0.x/ -->
- </struts>
SSH-Struts第一弹:ActionSupport类的更多相关文章
- struts 中继承ActionSupport类
理论上Struts 2.0的Action无须实现任何接口或继承任何类型,但是,我们为了方便实现Action,大多数情况下都会继承 com.opensymphony.xwork2.ActionSuppo ...
- (一)、Struts第一天
(一).Struts第一天 1. JavaWeb知识回顾 n 客户端编程 HTLM/CSS/JS n XML技术 会写XML * 基本语法 * DTD * Schema 会读XML * Dom4J读取 ...
- Spring Boot 第一弹,问候一下世界!!!
持续原创输出,点击上方蓝字关注我吧 目录 前言 什么是Spring Boot? 如何搭建一个Spring Boot项目? 第一个程序 Hello World 依赖解读 什么是配置文件? 什么是启动类? ...
- 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog
[源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...
- typecho流程原理和插件机制浅析(第一弹)
typecho流程原理和插件机制浅析(第一弹) 兜兜 393 2014年03月28日 发布 推荐 5 推荐 收藏 24 收藏,3.5k 浏览 虽然新版本0.9在多次跳票后终于发布了,在漫长的等待里始终 ...
- Struts2实现Preparable接口和【struts2】继承ActionSupport类
Struts2实现Preparable接口 实现preparable接口,实现public void prepare() throws Exception 方法.当你访问某问action指定方法之前, ...
- 我的长大app开发教程第一弹:Fragment布局
在接下来的一段时间里我会发布一个相对连续的Android教程,这个教程会讲述我是如何从零开始开发“我的长大”这个Android应用. 在开始之前,我先来介绍一下“我的长大”:这是一个校园社交app,准 ...
- 【struts2】继承ActionSupport类
在Struts2中,Action可以不实现任何特殊的接口或者继承特殊的类,仅仅是一个POJO(Plain Old Java Object,简单的Java对象)就可以:也可以实现Xwork2中的Acti ...
- struts2为什么action要继承actionSupport类
我们为了方便实现Action,大多数情况下都会继承com.opensymphony.xwork2.ActionSupport类, 并重载(Override)此类里的String execute()方法 ...
- Hadoop基础-MapReduce的工作原理第一弹
Hadoop基础-MapReduce的工作原理第一弹 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 在本篇博客中,我们将深入学习Hadoop中的MapReduce工作机制,这些知识 ...
随机推荐
- iterator and iterable
前者是迭代器 后者是接口,List等继承这个接口
- 最好的vim教程莫过于vimtutor
最好的vim教程莫过于vimtutor 直接运行vimtutor即可
- Java——Swing
- JavaScript学习笔记——变量和数据类型
一.javascript命名规范 1. 严格区分大小写 2. 变量的命名必须以字母或 _或 $开头,余下的部分可以是任意的字母,数字,或者是 _或者是$ 3.不能用关键字或者是保留字命名. 4.jav ...
- Android学习笔记——xml
转自http://blog.csdn.net/sam_zhang1984 解析 XML 有两种方式: SAX 和 DOM .它们各有利弊. DOM 是把 XML 文档全部装载到内存中,然后当成一树进行 ...
- 深入浅出MyBatis
参考文献:深入浅出MyBatis MyBatis功能架构图: MyBatis内部原理流程图: 详情见:深入浅出MyBatis
- js日期计算及快速获取周、月、季度起止日,获取指定日期周数以及星期几的小例子
JS获取日期时遇到如下需求,根据某年某周获取一周的日期.如开始日期规定为星期四到下一周的星期五为一周. 格式化日期: function getNowFormatDate(theDate) { var ...
- Request.GetOwinContext()打不到
Although it's in the Microsoft.Owin.Host.SystemWeb assembly it is an extension method in the System. ...
- phpcms使用细节
1.在模板中使用php语句 <?php for ($i=0; $i < 10; $i++) { echo $i."#######<br>"; }?& ...
- Intellij Idea中运行tomcat 报內存溢出 解决方案 火龙战士 火龙战士
在Run/Debug configuration 的你要运行行的tomcat里面的 vm options里面输入 -server -XX:PermSize=128M -XX:MaxPermSize=2 ...