java 没有为命名空间 / 和操作名称 HelloWorld 映射的操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7776969/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
There is no Action mapped for namespace / and action name HelloWorld
提问by Adarsh R S
I am trying to run a simple struts 2 HelloWorld application ,when i run it ,says "There is no Action mapped for namespace / and action name HelloWorld.Can somebody please help.
我正在尝试运行一个简单的 struts 2 HelloWorld 应用程序,当我运行它时,说“没有为命名空间/和操作名称 HelloWorld 映射的操作。有人可以帮忙吗?
WARNING: Could not find action or result
There is no Action mapped for namespace / and action name HelloWorld. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
回答by Zohaib
->Check that the action is mapped into the struts file ->action name in jsp, in struts.xml and name of action class all are exactly same ->is action mapping in struts-config.xml is under some package, then include the package in the url (eg while submitting form, url must include name of package)
->检查action是否映射到struts文件->jsp中的action名,struts.xml中的action类名都完全一样->struts-config.xml中的action映射是否在某个包下,然后include url 中的包(例如,在提交表单时,url 必须包含包的名称)
回答by Sridhar
More often that not when struts gets the action name wrong even when there's nothing wrong with struts.xml, the problem is that the tag lib definition is missing from the jsp file.
更常见的是,即使 struts.xml 没有任何问题,但当 struts 获取操作名称错误时,问题在于 jsp 文件中缺少标签库定义。
回答by Krishna
Maybe you have made a mistake in the struts.xml file. There are several ways to configure this file; here is an example:
也许您在 struts.xml 文件中犯了错误。有几种方法可以配置这个文件;这是一个例子:
<?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>
<package name="default" extends="struts-default">
<action name="helloWorld" class="controller.HelloWorld">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
If you do this in this way just make sure that you have to call action from the jsp by Action name only; You do not need to write .action
: that will cause error.
如果您以这种方式执行此操作,请确保您必须仅通过操作名称从 jsp 调用操作;你不需要写.action
:那会导致错误。
This could answer your question.
这可以回答你的问题。