尚硅谷公开课--struts2--5--ActionSuport
2015-08-11 00:00
323 查看
ActionSuport,默认的Action类。在配置struts2.xml中的action结点时,如果不填写action的class属性,则其默认值为ActionSuport。可以在struts2的默认配置文件中查看该值,位置在文件中struts-default包配置的最后,也是此默认配置文件的最后:
可以看到我们没有指定action的class属性,但是页面同样可以正常跳转,打开com.opensymphony.xwork2.ActionSupport的源码,找到execute函数
ActionSuport除了实现Action接口外,还实现了其它几个接口,实现了字段验证,国际化等功能。限于能力,现只作记录。
<package name="struts-default" abstract="true"> ... ... <default-class-ref class="com.opensymphony.xwork2.ActionSupport" /> </package>在struts2.xml中添加一个action,内容如下:
<action name="TestActionSuportAction"> <result>/test-ActionSuportAction.jsp</result> </action>添加一个jsp页面:test-ActionSuportAction.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Insert title here</title> </head> <body> <h4>Test ActionSuport</h4> </body> </html>在index.jsp中添加一个链接
<a href="TestActionSuportAction.do">Test ActionSuport</a>运行项目
可以看到我们没有指定action的class属性,但是页面同样可以正常跳转,打开com.opensymphony.xwork2.ActionSupport的源码,找到execute函数
public String execute() throws Exception { return SUCCESS; }此函数返回了一个字符串,其值为 success ,在action中,虽然没有配置result的name属性,但其默认属性为success,所以可以正常跳转。也就是说上面的action等价于:
<action name="TestActionSuportAction" class="com.opensymphony.xwork2.ActionSupport" method="execute"> <result name="success">/test-ActionSuportAction.jsp</result> </action>ActionSuport类实现了Action接口,Action接口的内容如下:
package com.opensymphony.xwork2; public interface Action { public static final String SUCCESS = "success"; public static final String NONE = "none"; public static final String ERROR = "error"; public static final String INPUT = "input"; public static final String LOGIN = "login"; public String execute() throws Exception; }可以看到SUCCESS常量和execute()方法均在此接口中声明。
ActionSuport除了实现Action接口外,还实现了其它几个接口,实现了字段验证,国际化等功能。限于能力,现只作记录。
相关文章推荐
- cxf-2.7.3+spring3.0.7
- java中的注解
- Win10下Eclipse插件EasyShell兼容问题处理
- [转]java 为什么wait(),notify(),notifyAll()必须在同步方法/代码块中调用?
- 垃圾收集器与内存分配策略
- Eclipse启动参数
- java中的方法大全
- 【转】Java垃圾收集器
- Java心得10
- Velocity + Spring定时器 生成静态页面
- spring 注解注入方式
- Spring MVC 4值传递
- JAVA class文件中的符号引用
- Struts2文件的上传
- Struts2中通配符的使用
- java中的代码块理解
- 根据XML文件的id自动写java文件的声明方法和findViewById方法
- Java中多组输入的方式
- Java 连接MS Access数据库
- Java多线程:线程状态