2013年9月2日星期一

struts2 how pure annotation always There is no Action mapped fornamespace

Error message :
There is no Action mapped for namespace [/ test] and action name [gogo! go] associated with context path [/ sh].
Paste Code:
package com.sh.action.test;
import javax.annotation.Resource;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

//父包
@ParentPackage("struts-default")
@Namespace("/test")
@Results({ @Result(name = "error", location = "/wrong.jsp") })
@ExceptionMappings( { @ExceptionMapping(exception = "java.lange.RuntimeException", result = "error") })
public class TstAction extends ActionSupport{

private static final long serialVersionUID = 1L;
@Action(value="gogo",results={
@Result(location="/index.jsp",type="",name="success"),
@Result(location="/error.jsp",type="",name="fail")})
public String go()throws Exception{
return "success";
}
public String execute(){
return "success";
}
}

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 请求参数的编码方式 -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开 -->
<constant name="struts.action.extension" value="action,do,go,qqi" />
<!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.devMode" value="false" />
<!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<!-- 指定由spring负责action对象的创建 -->
<constant name="struts.objectFactory" value="spring" />
<!-- 是否开启动态方法调用 -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />


</struts>   

  <body>
     <a href="test/gogo!go.do">登   录 </a>
  </body>

------ Solution ------------------------------------- -------
download struts2-config-browser-plugin-2.3.15.1.jar, open http://localhost:8080/ {yourapp} / config-browser/actionNames.action see your actual Action ; information.
------ Solution ---------------------------------------- ----
using struts2 pure annotate the document which has as an example . Has been added after the struts2-convention-plugin.jar
Your struts.xml which no pure annotation scanning is enabled . And the default parent package to use convention-default instead of struts-default.
struts.xml adding specify all the parent package for the convention-default

default plug-in scanner package is the package name contains action, actions, struts, struts2 package and its subpackages are annotated classes
Your package name of the action here already contains action as long as the parent package will be able to access the specified
you are using struts2-config-browser-plugin.jar, open
http://localhost:8080/ yourProject / config-browser/actionNames.action
See all mapped successfully able to see whether the action has been successful
------ For reference only -------------------- -------------------
Great God in what ?
------ For reference only -------------------------------------- -
you this go () method to go yet ?
------ For reference only -------------------------------------- -
@ Action (value = "gogo") configuration instead of the entire class , rather just go that way


login
------ For reference only - --------------------------------------
your nameSpace is / test but you not defined nameSpace
------ For reference only ----------------------------------- ----
@ Action value mean you rather with the corresponding login name = login

login
------ For reference only --- ------------------------------------
not enough to namespace using the " / " trial try
------ For reference only ------------------------------------- -

cattle learned a lot

没有评论:

发表评论