Struts2没有针对命名空间映射的Action和与上下文路径关联的操作名称

我是Struts2的初学者,我知道这个问题已经在这里问了很多次,但我试着解决它并在这里阅读了很multithreading,花了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

   Struts2Test  index.jsp   contextConfigLocation  /WEB-INF/spring-context.xml /WEB-INF/spring-mvc.xml    org.springframework.web.context.ContextLoaderListener   struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter  actionPackages tw.com.rrstudio.java.test     HTTP://java.sun.com/jsp/jstl/core /WEB-INF/lib/tld/c.tld   *.jsp UTF-8    struts2 /*   springmvc org.springframework.web.servlet.DispatcherServlet  contextConfigLocation /WEB-INF/spring-mvc.xml  1   springmvc /*   10   

还有,struts.xml

             /WebContent/error.jsp   /WebContent/index.jsp /WebContent/TestAction.jsp    

的index.jsp

        Index of Struts2Test   

Index of Struts2Test


服务器是Tomcat 8.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结果。

现在我不知道,欢迎提出任何建议或提示……

与以下问题相关的问题:没有为与上下文路径关联的命名空间和操作名称映射的操作

如果使用url调用操作,请确保将此URL映射到struts配置。 要解决url映射问题,可以使用config-browser插件。 只需将此插件添加到您的项目依赖项中,当它部署时,您可以访问一个网站,显示运行时配置以及可用的URL以调用该操作。 例如,如果您在端口8080上本地运行Tomcat并在context部署您的应用程序,那么您可以访问该插件的URL

 http://localhost:8080/[context]/config-browser/index.action 

您可以单击侧栏上命名空间下操作页面上的任何可用操作。 另请注意,如果在程序包中找不到您的操作,则它可能位于default程序包中。 Struts在default命名空间中进行额外搜索,以查找不在URL映射的命名空间中的操作。


查看config-browser插件以调试配置问题。

要将url正确映射到操作,需要两个参数:操作名称和命名空间。

Struts在启动时加载xml配置,它应该知道struts.xml的位置。 默认情况下,它在类路径上查找具有已知名称的文件,如struts.xml 。 然后它解析文档并创建运行时配置。 此配置用于查找操作URL的相应​​配置元素。 如果在请求期间未找到此类元素,则返回404错误代码,并显示以下消息: There is no Action mapped for namespace and action name

此消息还包含用于查找操作配置的命名空间和操作名称。 然后,您可以在struts.xml检查配置设置。 有时, ActionMapping存储的动作名称和命名空间指向错误的动作。 这些值由ActionMapper确定,它可以具有不同的实现,由插件使用。

还有另一个可能会影响此映射器和映射的设置,但如果您收到此消息,则使用URL时不会映射运行时配置中的任何操作配置。 如果您无法实现应使用的URL,可以尝试使用config-browser插件查看可供使用的URL列表。