---
title: "Struts内置Action类"
author: "chenyubo"
date: "2008-07-28T20:25:28Z"
tags: ["Apache", "JSP", "Struts", "XML", "编程"]
slug: "struts-action"
draft: false
lastmod: "2008-07-28T20:25:28Z"
id: 220761
url: "https://chenyubo.iteye.com/blog/220761"
---

Struts内置Action类
关键字: Struts 
    有一些常用的Action类Struts 已经帮你写好了，如果有不知道的可以来这里看看。

1 org.apache.struts.actions.ForwardAction

forwardAction的特点是利用控制器转发请求。 这样做比直接用链接转向的好处是控制器能够创建和这个表单对应的ActionForm对象，把用户输入表单数据组装到ActionForm中。

具体操作也很简单 比如：

页面：

```java
html:link page="/forword.do"
struts-config.xml 的mapping：
action path="/forword" parameter="next.jsp" type=org.apache.struts.actions.ForwordAction
scope="request" name="nextActionForm" validate="ture" input="/firstjsp.jsp"
```


当点击页面链接之后，ActionServlet就把请求转发给ForwardAction了，ForwardAction再把请求转发给parameter元素中的next,jsp 页面。

2  org.apache.struts.actions.IncludeAction

这个类的功能其实没有太多的优势所以笔者不推荐使用

3  org.apache.struts.actions.DispatchAction

这个类的用途是实现了按业务实体划分类，比如以前想要实现对一个Object进行update与insert操作，实际是建立两个操作类，而现在可以将这些类合并，并且将相同的部分提出来，简化了编程。

4  org.apache.struts.actions.LookupDispatchAction

这个类是笔者重点推荐的类。这个类最大的特点可以在一个表单中轻松实现多个Submit按钮。