struts2 纯注解 怎么老是There is no Action mapped for namespace

wyang0126 2013-08-27 04:55:58
报错信息:
There is no Action mapped for namespace [/test] and action name [gogo!go] associated with context path [/sh].
贴上代码:
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>
...全文
1830 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wyang0126 2013-08-28
  • 打赏
  • 举报
回复
引用 5 楼 suciver 的回复:
使用struts2纯注解这个文档里面都有原样的例子的。在已经加入struts2-convention-plugin.jar后 你的struts.xml里面都没启用纯注解的扫描。而且默认的父包要用convention-default不是struts-default。 struts.xml中加上指定所有的父包为convention-default <constant name="struts.convention.default.parent.package" value="convention-default" /> 默认的插件扫描包是包名中包含action,actions,struts,struts2的包及其子包下的有注解的类 你这里的action的包名已经包含了action了只要父包指定就能访问了 你在用struts2-config-browser-plugin.jar,打开 http://localhost:8080/你的工程名/config-browser/actionNames.action 查看所有成功映射的action就能看到是否已经成功了
牛 学到很多东西
wenjie4892543 2013-08-28
  • 打赏
  • 举报
回复
还不行就namespace使用“/”试试
wenjie4892543 2013-08-28
  • 打赏
  • 举报
回复
@Action value的意思是你对应的login 相当与name = login <a href="test/gogo.action">登 录 </a>
harrisonkao 2013-08-28
  • 打赏
  • 举报
回复
你的nameSpace是/test 可是你没定义nameSpace
suciver 2013-08-28
  • 打赏
  • 举报
回复
使用struts2纯注解这个文档里面都有原样的例子的。在已经加入struts2-convention-plugin.jar后 你的struts.xml里面都没启用纯注解的扫描。而且默认的父包要用convention-default不是struts-default。 struts.xml中加上指定所有的父包为convention-default <constant name="struts.convention.default.parent.package" value="convention-default" /> 默认的插件扫描包是包名中包含action,actions,struts,struts2的包及其子包下的有注解的类 你这里的action的包名已经包含了action了只要父包指定就能访问了 你在用struts2-config-browser-plugin.jar,打开 http://localhost:8080/你的工程名/config-browser/actionNames.action 查看所有成功映射的action就能看到是否已经成功了
紫翎观星 2013-08-28
  • 打赏
  • 举报
回复
下载struts2-config-browser-plugin-2.3.15.1.jar,打开http://localhost:8080/{yourapp}/config-browser/actionNames.action看你的实际Action information。
  • 打赏
  • 举报
回复
@Action(value="gogo") 配置的不是整个类的,, 而单单 是那个go方法 <a href="test/tst!gogo.action">登 录 </a>
tony4geek 2013-08-27
  • 打赏
  • 举报
回复
你这个 go() 方法进去了吗 ?
wyang0126 2013-08-27
  • 打赏
  • 举报
回复
大神 在哪?

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧