2
回答
struts2注解配置@Action报错,求大神???谢谢!!!
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

在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]



举报
htmlCssJs
发帖于4年前 2回/1K+阅
顶部