Action的实现方式
第一种:
在web.xml中添加配置
<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>

在structs.xml中添加配置
<struts>
<!--extends必须写,直接或者间接继承struts-default name自定义 -->
<package name="hello" extends="struts-default">
<!-- name是请求名称,不要写/;class对应action完全限定名=包名+类名 -->
<action name="hello" class="cn.sxt.action.HelloAction">
<!-- result是结果集 name和对应action中的方法的返回值匹配,默认是success -->
<result name="success">/index.jsp</result>
</action>
</package>
</struts>

action实现类
package cn.sxt.action;

public class HelloAction {
public HelloAction() {
System.out.println("constructor");
}
public String execute(){
System.out.println("hello struts2");
return "success";
}
}
第二种实现方法 实现接口action
package cn.sxt.action;

import com.opensymphony.xwork2.Action;

public class InterfaceAction implements Action{

public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("interface action");
return SUCCESS;
}
}
第三种实现方法 继承ActionSupport
package cn.sxt.action;

import com.opensymphony.xwork2.ActionSupport;

public class ExtendsAction extends ActionSupport{

/**
*
*/
private static final long serialVersionUID = 1L;

}

structs2的action实现方式的更多相关文章

  1. MVC 在视图中获取当前的Controller、Action的方式

    在视图中获取Controller和Action的方式: Controller: @ViewContext.RouteData.Route.GetRouteData(this.Context).Valu ...

  2. Structs2中Action返回json到前台方法

    1.传统方式JSON输出 这一点跟传统的Servlet的处理方式基本上一模一样,代码如下 01 public void doAction() throws IOException{ 02        ...

  3. action解耦方式

    ServletAction方式,必须要有Servlet容器作支持 package com.hanqi.action; import javax.servlet.ServletContext; impo ...

  4. action 耦合方式

    //ActionContext 方式 package com.hanqi.action; import java.util.Map; import com.opensymphony.xwork2.Ac ...

  5. [水煮 ASP.NET Web API2 方法论](3-7)默认 Action 请求方式以及 NonActionAttribute

    问题 在 Controller 中有一个 public 的方法,但是又不想将这个 publlic 方法暴露成为一个 API. 解决方案 ASP.NET Web API 中,正常是通过 HTTP 谓词来 ...

  6. MVC Action控制方式

    1.Controller 的OnActionExecuting中控制 protected override void OnActionExecuting(ActionExecutingContext ...

  7. Struts 2 实现Action的几种方式_java - JAVA

    文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 Action用于处理用户的请求,因此也被称为业务控制器.每个Action类就是一个工作单元,Struts 2框架负责将用 ...

  8. 4.Struts2中Action的三种访问方式

    1.传统的访问方式-很少使用 通过<action>标签中的method属性,访问到action中的具体方法 具体实现: 1.action代码 import com.opensymphony ...

  9. SpringMVC(四) RequestMapping请求方式

    常见的Rest API的Get和POST的测试参考代码如下,其中web.xml和Springmvc的配置文件参考HelloWorld测试代码中的配置. 控制类的代码如下: package com.ti ...

随机推荐

  1. 软件测试(二)PICT的使用 组合测试方法(两两组合测试,可遍历组合测试)

    一.两两组合测试 # # 两两组合测试 # PLATFORH: x86, ia64, amd64 CPUS: Single, Dual, QUad PAHL: 120MB, 1GB, 4GB, 64G ...

  2. java Apache common-io 讲解

    Apache common-io用户指南 用户指南 Commons-io 包含utility classes,endian classes,line iterator,file filters,fil ...

  3. Dialog插件artDialog

    经本人测试,发现没有layer好用,因为artDialog不能拖拽.不过除了拖拽,其他还蛮简洁的,在自定义上的灵活性也还可以.下面是我自己写的测试demo. <!DOCTYPE html> ...

  4. 张鑫旭:Promise异步编程模式

    参考文章: http://www.zhangxinxu.com/wordpress/2014/02/es6-javascript-promise-%E6%84%9F%E6%80%A7%E8%AE%A4 ...

  5. SQL Server 数据库备份失败解决方法

    问题:System.Data.SqlClient.SqlError: 无法使用备份文件 'D:\20160512.bak',因为原先格式化该文件时所用扇区大小为 512,而目前所在设备的扇区大小为 4 ...

  6. java 连接Kafka报错java.nio.channels.ClosedChannelExcep

    Java 客户端连接Kafka报如下错误 java.nio.channels.ClosedChannelExcep 是由于Kafka server.properties中的advertised.hos ...

  7. HDU 1535 Invitation Cards (最短路)

    题目链接 Problem Description In the age of television, not many people attend theater performances. Anti ...

  8. Oracle新建数据库,并导入dmp文件

    1:安装Oracle及新建数据库 Oracle 11g安装图解 http://www.cnblogs.com/qianyaoyuan/archive/2013/05/05/3060471.html h ...

  9. 动态获取UILabel的bounds

    在使用UILabel存放字符串时,经常需要获取label的长宽数据,本文列出了部分常用的计算方法. 1.获取宽度,获取字符串不折行单行显示时所需要的长度 CGSize labelBounds = [s ...

  10. 系统架构之负载均衡【F5\nginx\LVS\DNS轮询\】

    在做系统架构规划的时候,负载均衡,HA(高可用性集群,是保证业务连续性的有效解决方案,一般有两个或两个以上的节点,且分为活动节点及备用节点,当活动节点出现故障的时候,由备用节点接管)都是经常需要考虑的 ...