相信大家一定看到了两个class中定义了一样的action,不过看类的元数据,是不同的命名空间。这里比较重要(对我来说)的是

@Action(value = "/login", results = {
@Result(name = "sucess", location = "/index.jsp"),
@Result(name = "chain", location = "chain", type = "chain"),// 同namespace下
// chain
@Result(name = "otherNsChain", type = "chain", params = { "namespace",
"/user", "actionName", "chain" }),// 不同namespace下
@Result(name = "redirect", type = "redirect", location = "redirect.action"),// 同namespace
@Result(name = "otherNsRedirect", type = "redirect", location = "/user/redirect.action"),// 不同namespace
@Result(name = "redirectAction", type = "redirectAction", params = {
"actionName", "redirectAction" }),// 同namespace
@Result(name = "otherNsRedirectAction", type = "redirectAction", params = {
"namespace", "/user", "actionName", "redirectAction" }) // 不同namespace
})

这里面results的配置,当result的type是chain的时候,如果是同一个命名空间,那么就可以直接写一个
action的name,如果加上后缀名比如.action的话struts就会报错,找不到execute()方法,如果不是同一个命名空间下,则需要
添上params,params是一个String数组形式的容器,{“key1”,“value1”,“key2”,“value2”}以这种形式书
写,关与params的更多信息可以参考xwork-core包里的

com.opensymphony.xwork2.ActionChainResult.class

。redirect的一致,如果在不同的命名空间,直接写命名空间+action的名字。
redirectAction的和chain差不多,但也有些许的区别。redirectAction没有location的配置,action的
name需要在params里面配置,key为actionName,namespace也需要在params里面配置,key为namespace。更
多的请参考struts-core下的

org.apache.struts2.dispatcher.ServletActionRedirectResult.class

。下面附上一些常用的几个result type的类

 <result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
</result-types>
  1. 基本上常用的以上都有了,包括上面提到的chain和redirectAction。 其实这些在struts-default.xml 也可以找到 。这些类里面有他们可接受配置的demo。
  2. 写2个在搭建环境的时候遇到的异常。
  3. java.lang.NoSuchMethodException:
    com.struts2.action.IndexAction.execute()
    可能是是配置有问题,比如我在上文说的在action的name中加上了后缀名或者也可能是在配置的时候action名前写了一个/ 。@Result(name="chain", location = "chain",type="chain")这句代码如果在location的chain前加一个/,可能也会造成这个异常。
    • 还有一个异常是 提示没有create方法,这个可能是因为struts里面rest的插件和action冲突了。
    • 注:以上两个异常不一定就是我说的问题引发的,真正的原因还是需要你自己去细细排查来确认的。

Struts2 注解模式的更多相关文章

  1. Annotation(四)——Struts2注解开发

    Hibernate和Spring框架的开发前边总结了,这次看一下流行的MVC流程框架Struts2的注解开发吧.Struts2主要解决了从JSP到Action上的流程管理,如何进行Uri和action ...

  2. Struts2注解开发

    Hibernate和spring框架的开发前边总结了,这次看一下流行的MVC流程框架Struts2的注解开发吧.Struts2主要解决了从JSP到Action上的流程管理,如何进行Uri和action ...

  3. struts2注解

    一.配置web.xml <filter> <filter-name>struts2</filter-name> <filter-class>org.ap ...

  4. Struts2注解使用说明

    Struts2注解 1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包 必须导入struts2-convention-plugin-2.3.15.jar包, ...

  5. Struts2注解 特别注意

    1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包 必须导入struts2-convention-plugin-2.3.15.jar包,它在struts2安 ...

  6. spring的配置模式与注解模式基础

    “依赖注入”是spring的核心特征,在Web服务器(如Tomcat)加载时,它会根据Spring的配置文件中配置的bean或者是通过注解模式而扫描并装载的bean实例自动注入到Application ...

  7. Struts2注解学习1

    这是开博的第一篇,我希望每天把我学到的东西记录下来,成为一个知识库,方便以后的学习和分享 在项目中看到用struts2注解来做,很方便,做了一个用户登录的例子 1.加载所需jar包 commons-f ...

  8. Struts2 注解(转)

    转自:http://blog.csdn.net/wwwqvod/article/details/6214431 也叫Zero Configuration(零配置),它省去了写xml文件的麻烦,可以直接 ...

  9. struts2注解redirect传递参数解决方案时,中国的垃圾问题

    struts2注解redirect传递参数解决方案时,中国的垃圾问题 试过很多方法  tomcat 编码  .字符串转换 .URLEncoder  .. 但是,没有解决方案,然后仔细阅读   stru ...

随机推荐

  1. 点击超链接打开本地QQ

    2014年6月4日 10:20:18 张志斌 这个功能实际上是属于腾讯的推广项目"一键加群"功能: http://qun.qq.com/join.html 用户必须有自己的群,登录 ...

  2. java 遍历指定目录下的文件夹并查找包含指定关键字的文件

    输入指定关键字,在制定目录中查找包含关键字的文件,返回包含指定关键字的文件路径. package net.xsoftlab.baike; import java.io.File; import jav ...

  3. px、pt、ppi、dpi、dp、sp之间的关系

    http://www.woshipm.com/pmd/176328.html 各自的定义: px:pixel,像素,电子屏幕上组成一幅图画或照片的最基本单元 pt: point,点,印刷行业常用单位, ...

  4. SRILM Ngram 折扣平滑算法

    关于n-gram 语言模型,大部分在这篇博客里 记过了,   SRILM 语言模型格式解读 , 其实看完了,ngram的大概用法都比较清楚了, 但是关于平滑算法,一直很模糊,就晓得一个"劫富 ...

  5. 了解一下LDC

    转自: Linguistic Data Consortium (LDC) 因为Kaldi里面各种语料涉及到LDC,搜罗一下,好像并没有相应的教程和网站用法.... 搞 NLP 的人经常会听到一个神秘的 ...

  6. 【转】HTML5 API——无刷新更新地址 history.pushState/replaceState 方法

    (window.location)在通过JavaScript更改以后,浏览器都会通过刷新来到达你更改后的URL(location的意思就是位 置..) 而在JavaScript MVC开始流行之后,通 ...

  7. WebStorm failing to start with 'idea.system.path' error

    WebStorm failing to start with 'idea.system.path' error Ask Question up vote 2 down vote favorite   ...

  8. MySQL CPU %sys 高的案例分析(三)

    [现象] 最近有台服务器晚上CPU告警,系统抓取的故障期间的snapshot显示CPU %sys较高,同时context switch在300K以上. 是否过高的context switch引起的%s ...

  9. 模拟POST、Get 请求的工具----APIpost(中文版POSTMAN)

    模拟POST.Get 请求的工具----APIpost(中文版POSTMAN) 快速生成.一键导出api文档 在线模拟调试,结果实时返回 模拟登录后请求API 支持团队协作 官网:https://ww ...

  10. 一个简单的日志函数C++

    有时候程序总是会发生意想不到的情况,为了方便排查错误的情况,还是写日志比较方便.这里自己写了一个简单的函数,能实现基本的功能. BOOL WriteLog(char * DataBuffer) { C ...