`

4.struts2在action中调用指定方法

阅读更多
上一篇已经给大家介绍了struts的一些基本配置。今天来给大家介绍一下关于struts的action中如何调用指定方法。

首先大家都知道,action默认调用的是execute方法,那么如何调用指定的方法呢?

  //方式一:通过配置method属性,来调用指定方法

<action name="user" class="com.hx.web.UserAction" method="add"> 
  <result>user.jsp</result> 
  <result name="error">adduser.jsp</result> 
</action>

  //方式二:直接在要请求的action后面加上 !方法  即可,例如
我们想请求userAction中的add()方法,那么我们可以直接在url中写成:localhost:port/项目名/user!add.action即可。

  //最后给大家说一下关于action类的划分问题

大家在公司工作的过程中,应该好多人都纠结action类如何进行划分。

//1>首先可以根据相关对象进行划分
  比如说,有一个UserAction类,你又有两个方法login(),editUser(),这两个方法都是和user相关的,所以你可以把他们都放到UserAction中。
//2>就是我们最常用的,根据业务逻辑划分
比如说把一个crud放到一个action中,这样维护起来比较容易。但是用该方法划分时,一个action中业务逻辑不能太复杂,如果很复杂你就需要拆分成多个action了。。。

1
1
分享到:
评论

相关推荐

    org.apache.struts缺少所需包

    import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.actions.DispatchAction等缺少

    org.springframework.web.struts-3.1.0.M2.jar

    org.springframework.web.struts-3.1.0.M2.jar

    org.apache.struts2.dispatcher.FilterDispatcher

    org.apache.struts2.dispatcher.FilterDispatcher

    struts2-core.jar

    struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...

    Manning.Struts in Action

    Manning.Struts in Action.rar Manning.Struts in Action.rar

    Struts2详解,Struts2与Struts1的区别

    新手必备,看完绝对思路清晰。醍醐灌顶啊! 一. Struts2介绍 1. Struts2简介 2. Struts2和Struts1的常见区别 ...二. Struts2入门 ... 3. 快速配置Struts2环境 ... 4. 开发一个Struts2简单实例 ... Struts2中常用标签

    Struts2属性文件详解

    该属性指定是否允许在Struts 2标签中使用表达式语法,因为通常都需要在标签中使用表达式语法,故此属性应该设置为true,该属性的默认值是true. struts.devMode 该属性设置Struts 2应用是否使用开发模式.如果设置该属性...

    Manning.Struts.2.in.Action.May.2008

    Manning.Struts.2.in.Action.May.2008

    解决MyEclipse下开发Struts异常:org.apache.struts.taglib.bean.CookieTei.doc 下载

    绝对可以解决这个这个问题。Struts初学者绝对可以受用的方法。

    Struts2 chm文档

    7.Struts2介绍之使用链接标签.doc 8.Struts2入门.doc 9.Struts2学习进阶(基础篇1-7) 10.Struts2学习进阶(实例篇1)——struts2-blank-2.0.8实例学习.doc 11.改写Restful2ActionMapper让Struts2支持REST风格的URL...

    struts 2.2 api文档

    org.apache.struts2, org.apache.struts2.components, org.apache.struts2.components.template, org.apache.struts2.config, org.apache.struts2.dispatcher, org.apache.struts2.dispatcher.mapper, org.apache....

    Struts2入门教程(全新完整版)

    3.初识struts2配置文件 4 (1).web.xml文件 4 (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-default.xml 4 (5)其它配置文件 4 4.让MyEclipse提示xml信息 4 5.如何...

    spring-struts.jar

    META-INF/MANIFEST.MForg.springframework.web.struts.ActionServletAwareProcessor.class org.springframework.web.struts.ActionSupport.class org.springframework.web.struts.AutowiringRequestProcessor.class ...

    struts2.in.action

    Struts 2 is much more than a revision of the Struts 1 framework. If you hadn't yet heard anything about Struts 2, you might expect, based upon the name, to find a new release of that proven ...

    Struts课堂笔记.rar--struts2的struts.properties配置文件详解

    专为multipart请求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上传用) struts.multipart.saveDir The directory to use for storing uploaded files 设置存储上传...

    Struts2全解Struts2全解

    Namespace、自定义Action、路径问题、通配符、包含模块配置文件、默认Action、接受用户输入、服务器跳转、Action中访问web元素、简单数据校验、调用Action的自定义方法 5struts2国际化 ......... 6 struts2输入校验...

    struts2自定义标签案例详解

    Struts2中实现自定义标签很简单,主要分为3步: 1.创建taglib文件(.tld)...4. extended by org.apache.struts2.views.jsp.StrutsBodyTagSupport 5. extended by org.apache.struts2.views.jsp.ComponentTagSupport

    Practical.Apache.Struts2.Web.2.0.Projects

    Practical.Apache.Struts2.Web.2.0.Projects,网页开发很好的指导手册

    Struts2-ActionError-ActionMessage-Example

    Struts2-ActionError-ActionMessage-Example

    struts2 对action中的所有方法进行校验

    struts2对action中的所有方法进行校验

Global site tag (gtag.js) - Google Analytics