开发者社区> 问答> 正文

struts2注解配置@Action报错,求大神???谢谢!!!?报错

在struts.xml中配置action就没问题,用注解@Action的话就报错:

org.apache.struts2.dispatcher.Dispatcher warn
警告: Could not find action or result: /struts2/anno2.action
There is no Action mapped for namespace [/] and action name [anno2] associated with context path [/struts2]. - [unknown location]

struts.xml代码如下:

 <struts>
 	<package name="struts2" extends="struts-default">
  
 		<action name="TestAction" class="com.icss.test.TestAction">
 			<result name="success">/loginResult.jsp</result>
 			<result name="input">/login.jsp</result>
 		</action>
  
 		<action name="*-*-*" class="com.icss.test.{1}" method="{2}">
 			<result name="success">/{3}.jsp</result>
 			<exception-mapping result="ex" exception="Exception">
 			</exception-mapping>
 			<result name="ex">/index.jsp</result> 
 		</action>


                <action name="MyAction" class="com.icss.test.MyAction">
 			<result name="success">/myAction_result.jsp</result>
 		</action>
  
 		<action name="testAction2" class="com.icss.test.TestAction2">
 			<result name="success">/index.jsp</result>
 		</action>
  
 		<action name="registerValidateAction" class="com.icss.test.RegisterValidateAction">
 			<result name="success">/index.jsp</result>
 			<result name="input">/registerValidate.jsp</result>
 		</action>


               <action name="dynamicMethodAction" class="com.icss.test.DynamicMethodAction">
                       <result name="success">/dynamicMethodResult.jsp</result>
                       <allowed-methods>add, mul</allowed-methods>
               </action>
 
 	</package>
 </struts>

action代码:

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import com.opensymphony.xwork2.ActionSupport;

@ParentPackage("struts-default")
@Namespace(value="/")
public class AnnotationTest2 extends ActionSupport
{
 @Action(value="anno2")
 public String execute() throws Exception
 {
     System.out.println("annotation2 invoked...");
     return SUCCESS;
 }
 
 @Action(value="method")
 public String method()
 {
     System.out.println("method invoked...");
     return SUCCESS;
 }
}

我直接在地址栏输入:

http://localhost:8080/struts2/anno2.action

就会报错


在struts.xml中配置action就没问题,用注解@Action的话就报错:

org.apache.struts2.dispatcher.Dispatcher warn
警告: Could not find action or result: /struts2/anno2.action
There is no Action mapped for namespace [/] and action name [anno2] associated with context path [/struts2]. - [unknown location]



展开
收起
爱吃鱼的程序员 2020-06-22 13:38:50 635 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    信息量太少了吧?起码将你的那个acion贴出来。还有struts.xml也得贴出来。
    注解中你的namespace在哪配置了?回复<aclass='referer'target='_blank'>@htmlCssJs:@ParentPackage("struts-default")这个对于配置文件中package的name,不是extends在action代码中的第6行:@Namespace(value="/")

    2020-06-22 13:39:07
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载