spring 没有为与上下文路径 [/struts] 关联的命名空间 [/] 和操作名称 [] 映射的操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17829388/
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 [] associated with context path [/struts]
提问by java_newbie
I've looked through all similar Qs on stackoverflow but it didn't help, sorry. The main difference I have from all of them is that I got EMPTY action name in error message. Googling didn't help :( Hope someone just could give a hint where to look for the source of the problem. thx
我已经在 stackoverflow 上查看了所有类似的问题,但没有帮助,抱歉。我与所有这些的主要区别是我在错误消息中得到了 EMPTY 操作名称。谷歌搜索没有帮助:(希望有人可以提示在哪里寻找问题的根源。thx
message:
信息:
Stacktraces
There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58
..................
struts.xml:
struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/*" extends="struts-default">
<action name="login"
class="training.struts.action.LoginAction">
<result>login.jsp</result>
</action>
</package>
</struts>
web.xml:
网页.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Struts Lab</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Config -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/springServlet/appServlet/mvc-servlet.xml,
/WEB-INF/db/db-cfg.xml,
/WEB-INF/springServlet/application-security.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springServlet/appServlet/mvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- *** -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
well..image is impossible so the project structure is:
好吧..图像是不可能的,所以项目结构是:
src/main/java
----+training.struts.action.LoginAction.java
src/main/webapp
----+WEB-INF
--------+classes
-----------+struts.xml
--------+db
-----------+db-cfg.xml
--------+springServlet
-----------+appServlet
---------------+mvc-servlet.xml
-----------+application-security.xml
--------+index.jsp
--------+login.jsp
--------+web.xml
UPDATE: So sad to be stupid =( I've moved my login.jsp from WEB-INF to webapp root and that solved the problem.
更新:太愚蠢了=(我已经将我的 login.jsp 从 WEB-INF 移动到 webapp root 并解决了问题。
UPDATE2:I've made some investigation: if I remove "welcome-file-list" block from web.xml, container will look for "index.jsp" in webapp root to show as first view on application running. If I delete "index.jsp" then I'll got the identical exception message: There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]
UPDATE2:我进行了一些调查:如果我从 web.xml 中删除“welcome-file-list”块,容器将在 webapp 根目录中查找“index.jsp”以显示应用程序运行时的第一个视图。如果我删除“index.jsp”,那么我将收到相同的异常消息: 没有为命名空间 [/] 和与上下文路径 [/struts] 关联的操作名称 [] 映射的操作
So in my opinion if you have empty action name in error message with correct xml settings for struts, the first step should be start-up JSP availability checking.
因此,在我看来,如果错误消息中的操作名称为空且 struts 的 xml 设置正确,那么第一步应该是启动 JSP 可用性检查。
Cheers, guys.
干杯,伙计们。
采纳答案by java_newbie
OK, so I have placed login.jsp in a wrong place in my web-app folders structure. That was the mistake
好的,所以我将 login.jsp 放在了我的 web-app 文件夹结构中的错误位置。那是错误
回答by Aniruddha Das
Add the below blank action to you struts.xml file in "/"package namespace and it will show the index.html when you will only try to access your url (like appid.app.com) and it will not show the error. Normally it will add a blank action and app engine will redirect the blank action to your welcome file.
将以下空白操作添加到"/"包命名空间中的struts.xml 文件中,当您仅尝试访问您的 url(如 appid.app.com)时,它将显示 index.html,并且不会显示错误。通常它会添加一个空白操作,应用引擎会将空白操作重定向到您的欢迎文件。
<action name="" class="com.candi.actions.Dashboard" method="noAction">
<result name="success">index.jsp</result>
</action>
回答by Ankur Lathi
Add / in your namespace instead of /* :
在您的命名空间中添加 / 而不是 /* :
<package name="default" namespace="/" extends="struts-default">
Or if issue not resolved than you can use Config Browser Plugin.
或者,如果问题未解决,您可以使用Config Browser Plugin。
The Config Browser Plugin is a simple tool to help view an application's configuration at runtime. It is very useful when debugging problems that could be related to configuration issues.
Config Browser Plugin 是一个简单的工具,可帮助在运行时查看应用程序的配置。在调试可能与配置问题相关的问题时,它非常有用。
回答by user2761026
I changed the namespace in package tag to '/' and the problem resolved!!!
我将包标记中的命名空间更改为“/”,问题解决了!!!
回答by chenghong
For me, I changed the opening tag of the web.xml file from
对我来说,我将 web.xml 文件的开始标记从
<web-app>
to
到
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
回答by MayurB
Add the following package in struts.xml
在 struts.xml 中添加以下包
<package name="default" namespace="/" extends="struts-default">
<action name="login"
class="training.struts.action.LoginAction">
<result>login.jsp</result>
</action>
</package>

