没有为命名空间 [/] 映射的操作和与上下文路径 [/Struts2Test] 关联的操作名称 [登录]
There is no Action mapped for namespace [/] and action name [login] associated with context path [/Struts2Test]
我是Struts2的初学者,我知道这个问题在这里被问了很多次,但是我试图解决这个问题,在这里阅读了很多主题,花了6个小时仍然无法解决这行得通。真的需要更多建议...
这是我的包裹:
Struts2Test
+Struts2Test/src
+tw.com.rrstudio.java.test
-TestAction.java
+Struts2Test/build
+Struts2Test/WebContent
+Struts2Test/WebContent/META-INF
+Struts2Test/WebContent/WEB-INF/classes
+Struts2Test/WebContent/WEB-INF/lib
-Struts2Test/WebContent/WEB-INF/spring-context.xml
-Struts2Test/WebContent/WEB-INF/spring-mvc.xml
-Struts2Test/WebContent/WEB-INF/struts.xml
-Struts2Test/WebContent/WEB-INF/struts2-action.xml
-Struts2Test/WebContent/WEB-INF/web.xml
-Struts2Test/WebContent/error.jsp
-Struts2Test/WebContent/index.jsp
-Struts2Test/WebContent/TestAction.jsp
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context.xml
/WEB-INF/spring-mvc.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>tw.com.rrstudio.java.test</param-value>
</init-param>
</filter>
<jsp-config>
<taglib>
<taglib-uri>HTTP://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/tld/c.tld</taglib-location>
</taglib>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
还有,struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- struts 2.3.16.3 has problem of security,needing to set DynamicMethodInvocation=false -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.action.extension" value="do"/>
<constant name="struts.action.excludePattern" value="/jsp/.*?,/image/.*?,/css/.*?,/js/.*?,.*\.jsp"/>
<package name="default" extends="json-default" ></package>
<package name="Strut2Test" extends="json-default" >
<global-results>
<result name="SystemErrorPage">/WebContent/error.jsp</result>
</global-results>
<action name="login" class="tw.com.rrstudio.java.test.TestAction">
<result name="index">/WebContent/index.jsp</result>
<result name="success">/WebContent/TestAction.jsp</result>
</action>
</package>
</struts>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=login.action">
<title>Index of Struts2Test</title>
</head>
<body>
<h1>Index of Struts2Test</h1>
<form action="testAction" method="post">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</form>
</body>
</html>
服务器是Tomcat8.0.38,启动没有错误。但是当我访问
http://127.0.0.1:8080/Struts2Test/
http://127.0.0.1:8080/Struts2Test/login
它给我这个(如标题)错误,如果我访问
http://127.0.0.1:8080/Struts2Test/index.jsp
我会得到一个常规的 404 结果。
现在我不知道,欢迎任何建议或提示...
Issues related to: There is no Action mapped for namespace and action name associated with context path
如果您使用 URL 调用操作,请确保此 URL 映射到 Struts 配置。要解决 URL 映射问题,您可以使用 config-browser 插件。只需将这个插件添加到您的项目依赖项中,当它被部署时,您可以访问一个网站,该网站显示一个运行时配置,其中包含可用的 URLs 来调用该操作。例如,如果您在本地 运行 Tomcat 端口 8080 并在 context
部署了您的应用程序,那么您可以使用
访问插件的 URL
http://localhost:8080/[context]/config-browser/index.action
您可以单击边栏上命名空间下的操作页面上的任何可用操作。另请注意,如果您的操作未在包中找到,则它可能在 default
包中。 Struts 在 default
命名空间中对不在 URL.
映射的命名空间中的操作进行额外搜索
Check out the config-browser plugin to debug configuration
issues.
To map correctly url to the action two parameters are required: the
action name and namespace.
Struts loads xml configuration on startup and it should know the
location of the struts.xml
. By default it's looking on classpath to
find a file with known name like struts.xml
. Then it parses document
and creates a runtime configuration. This configuration is used to
find appropriate configuration element for the action url. If no such
element is found during request, the 404 error code is returned with
the message: There is no Action mapped for namespace and action name
.
Also this message contains a namespace and action names used to find
the action config. Then you can check your configuration settings in
struts.xml
. Sometimes the action name and namespace, stored in
ActionMapping
point to the wrong action. These values are determined
by the ActionMapper
which could have different implementation, used
by plugins.
There's also another setting that might affect this mapper and
mapping, but the point is the same if you get this message then URL is
used didn't map any action config in runtime configuration. If you
can't realize which URL you should use, you might try
config-browser plugin to see the list of URLs available to use.
查看 config-browser plugin 以调试配置问题。
在我们的 set-up 中,我们使用了 link:
http://localhost:8080/[context]/config-browser/index.do
在我们的例子中,我们发现我们在两个不同的文件夹级别有冲突的 struts.xml
文件。我所说的冲突是指它们内部的操作使用相同的名称重叠。
检查 struts.xml 中的常量 struts.action.excludePattern 以及是否存在用于登录的条目。在我的例子中,排除模式造成了问题。
如果您在基于 struts2 的应用程序
中进行 servlet 调用,则此方法适用
我收到这个错误,因为 struts.xml 文件没有放在正确的位置,什么是 src 文件夹! ('!' == 新秀惊喜):
ApplicationProjectRoot
|
|__Java Resources
| |
| |__src
| | |__struts.xml
| | |__any.package.app
| | |__AnyClass.java
| |
| |__Libraries
[...]
我是Struts2的初学者,我知道这个问题在这里被问了很多次,但是我试图解决这个问题,在这里阅读了很多主题,花了6个小时仍然无法解决这行得通。真的需要更多建议...
这是我的包裹:
Struts2Test
+Struts2Test/src
+tw.com.rrstudio.java.test
-TestAction.java
+Struts2Test/build
+Struts2Test/WebContent
+Struts2Test/WebContent/META-INF
+Struts2Test/WebContent/WEB-INF/classes
+Struts2Test/WebContent/WEB-INF/lib
-Struts2Test/WebContent/WEB-INF/spring-context.xml
-Struts2Test/WebContent/WEB-INF/spring-mvc.xml
-Struts2Test/WebContent/WEB-INF/struts.xml
-Struts2Test/WebContent/WEB-INF/struts2-action.xml
-Struts2Test/WebContent/WEB-INF/web.xml
-Struts2Test/WebContent/error.jsp
-Struts2Test/WebContent/index.jsp
-Struts2Test/WebContent/TestAction.jsp
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-context.xml
/WEB-INF/spring-mvc.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>tw.com.rrstudio.java.test</param-value>
</init-param>
</filter>
<jsp-config>
<taglib>
<taglib-uri>HTTP://java.sun.com/jsp/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/lib/tld/c.tld</taglib-location>
</taglib>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>10</session-timeout>
</session-config>
</web-app>
还有,struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- struts 2.3.16.3 has problem of security,needing to set DynamicMethodInvocation=false -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.action.extension" value="do"/>
<constant name="struts.action.excludePattern" value="/jsp/.*?,/image/.*?,/css/.*?,/js/.*?,.*\.jsp"/>
<package name="default" extends="json-default" ></package>
<package name="Strut2Test" extends="json-default" >
<global-results>
<result name="SystemErrorPage">/WebContent/error.jsp</result>
</global-results>
<action name="login" class="tw.com.rrstudio.java.test.TestAction">
<result name="index">/WebContent/index.jsp</result>
<result name="success">/WebContent/TestAction.jsp</result>
</action>
</package>
</struts>
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=login.action">
<title>Index of Struts2Test</title>
</head>
<body>
<h1>Index of Struts2Test</h1>
<form action="testAction" method="post">
<label for="name">Please enter your name</label><br/>
<input type="text" name="name"/>
<input type="submit" value="Say Hello"/>
</form>
</body>
</html>
服务器是Tomcat8.0.38,启动没有错误。但是当我访问
http://127.0.0.1:8080/Struts2Test/
http://127.0.0.1:8080/Struts2Test/login
它给我这个(如标题)错误,如果我访问
http://127.0.0.1:8080/Struts2Test/index.jsp
我会得到一个常规的 404 结果。
现在我不知道,欢迎任何建议或提示...
Issues related to: There is no Action mapped for namespace and action name associated with context path
如果您使用 URL 调用操作,请确保此 URL 映射到 Struts 配置。要解决 URL 映射问题,您可以使用 config-browser 插件。只需将这个插件添加到您的项目依赖项中,当它被部署时,您可以访问一个网站,该网站显示一个运行时配置,其中包含可用的 URLs 来调用该操作。例如,如果您在本地 运行 Tomcat 端口 8080 并在 context
部署了您的应用程序,那么您可以使用
http://localhost:8080/[context]/config-browser/index.action
您可以单击边栏上命名空间下的操作页面上的任何可用操作。另请注意,如果您的操作未在包中找到,则它可能在 default
包中。 Struts 在 default
命名空间中对不在 URL.
Check out the config-browser plugin to debug configuration issues.
To map correctly url to the action two parameters are required: the action name and namespace.
Struts loads xml configuration on startup and it should know the location of the
struts.xml
. By default it's looking on classpath to find a file with known name likestruts.xml
. Then it parses document and creates a runtime configuration. This configuration is used to find appropriate configuration element for the action url. If no such element is found during request, the 404 error code is returned with the message:There is no Action mapped for namespace and action name
.Also this message contains a namespace and action names used to find the action config. Then you can check your configuration settings in
struts.xml
. Sometimes the action name and namespace, stored inActionMapping
point to the wrong action. These values are determined by theActionMapper
which could have different implementation, used by plugins.There's also another setting that might affect this mapper and mapping, but the point is the same if you get this message then URL is used didn't map any action config in runtime configuration. If you can't realize which URL you should use, you might try config-browser plugin to see the list of URLs available to use.
查看 config-browser plugin 以调试配置问题。
在我们的 set-up 中,我们使用了 link:
http://localhost:8080/[context]/config-browser/index.do
在我们的例子中,我们发现我们在两个不同的文件夹级别有冲突的 struts.xml
文件。我所说的冲突是指它们内部的操作使用相同的名称重叠。
检查 struts.xml 中的常量 struts.action.excludePattern 以及是否存在用于登录的条目。在我的例子中,排除模式造成了问题。 如果您在基于 struts2 的应用程序
中进行 servlet 调用,则此方法适用我收到这个错误,因为 struts.xml 文件没有放在正确的位置,什么是 src 文件夹! ('!' == 新秀惊喜):
ApplicationProjectRoot
|
|__Java Resources
| |
| |__src
| | |__struts.xml
| | |__any.package.app
| | |__AnyClass.java
| |
| |__Libraries
[...]