没有与上下文路径[/Struts2Test]关联的名称空间[/]和操作名称[login]映射的操作. [英] There is no Action mapped for namespace [/] and action name [login] associated with context path [/Struts2Test]

查看:102
本文介绍了没有与上下文路径[/Struts2Test]关联的名称空间[/]和操作名称[login]映射的操作.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Struts2的初学者,我知道这个问题在这里已经问过很多遍了,但是我试图解决这个问题并在这里阅读了很多线程,花了6个小时仍然无法正常工作.确实需要更多建议...

I'm a beginner of Struts2, I know this question been asked in here much times, but I tried to solve it and read much much threads here, spend 6 hours and still can't get it work. Really need more suggestion...

这是我的包裹:

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

My 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

And also, 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>

该服务器是Tomcat 8.0.38,它启动时没有错误.但是当我访问

The Server is Tomcat 8.0.38, it starts with no error. But when I access

  • http://127.0.0.1:8080/Struts2Test/
  • http://127.0.0.1:8080/Struts2Test/login
  • http://127.0.0.1:8080/Struts2Test/
  • http://127.0.0.1:8080/Struts2Test/login

它给我这个(作为标题)错误,如果我访问

it gives me this(as title) error, and if I access

  • http://127.0.0.1:8080/Struts2Test/index.jsp

我会得到常规的404结果.

I will get a regular 404 result.

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

Now I have no idea, any suggestions or tips are welcome...

推荐答案

与以下问题有关:与上下文路径关联的名称空间和操作名称未映射任何操作

如果使用URL来调用动作,请确保将该URL映射到Struts配置.要解决URL映射问题,可以使用 config-browser 插件.只需将此插件添加到您的项目依赖项中,并在部署它后,就可以访问一个网站,该网站显示了运行时配置以及可用的URL来调用操作.例如,如果您在端口8080上本地运行Tomcat并将应用程序部署在context上,则可以使用以下命令访问插件的URL:

If you use URL to call an action, make sure this URL is mapped to the Struts configuration. To troubleshoot the issue with URL mapping you can use config-browser plugin. Simply add this plugin to your project dependencies and when it's deployed, you can access a website showing you a runtime configuration with available URLs to call the action. For example if you are running Tomcat locally on port 8080 and deployed your application at the context, then you can access the plugin's URL with

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

您可以在侧边栏名称空间下的操作"页面上单击任何可用的操作.另请注意,如果在包装上未找到您的操作,则可能在default包装中. Struts在default命名空间中进行其他搜索,以查找不在URL映射的命名空间中的操作.

You can click any action available on the actions page under the namespace on the sidebar. Also note that if your action is not found on the package it might be in the default package. Struts does additional search in the default namespace for the action that is not at the namespace mapped from the URL.

检出 config-browser 插件以调试配置 问题.

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在启动时加载xml配置,它应该知道 struts.xml的位置.默认情况下,它正在寻找类路径 查找一个已知名称的文件,例如struts.xml.然后解析文件 并创建运行时配置.此配置用于 找到适合操作网址的配置元素.如果没有 在请求期间找到元素,并返回404错误代码 消息:There is no Action mapped for namespace and action name.

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.

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

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.

还有另一个设置可能会影响此映射器, 映射,但要点是相同的,如果您收到此消息,则URL为 使用时未在运行时配置中映射任何操作配置.如果你 无法意识到您应该使用哪个网址,您可以尝试 配置浏览器插件以查看可用的URL列表.

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.

这篇关于没有与上下文路径[/Struts2Test]关联的名称空间[/]和操作名称[login]映射的操作.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆