在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]
信息量太少了吧?起码将你的那个acion贴出来。还有struts.xml也得贴出来。
注解中你的namespace在哪配置了?回复<aclass='referer'target='_blank'>@htmlCssJs:@ParentPackage("struts-default")这个对于配置文件中package的name,不是extends在action代码中的第6行:@Namespace(value="/")
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。