没有与命名空间[/]和操作名称[Test]映射的上下文路径[/ TestStruts]相关联的操作。 - [未知位置] [英] There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [unknown location]

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

问题描述

我在NetBeans 7.2.1中在struts 2.3.16上尝试我的第一个应用程序。它在输入URL时显示以下错误 - http:// localhost:8080 / TestStruts / Test.action (有一个 Test.jsp page)。

 警告:找不到操作或结果:/TestStruts/Test.action 
没有与上下文路径[/ TestStruts]相关联的名称空间[/]和操作名称[Test]映射的操作。 - [未知位置]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org。 apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
在org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
在org.apache。 struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
在org.apache。 catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
在org.apache.catalina.core。 StandardContextValve.invoke(StandardContextValve.java:123)
在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
在org.apache.catalina.core.StandardHostValve.invoke StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java: 936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:589)
在org .apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:1822)
在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
在java.util .concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Test.jsp 页面:

 < s:form namespace =/ TestStrutsaction =test> 
< table border =0class =>
< tr>

< td>
< s:textfield id =namename =namelabel =输入您的姓名/>
< / td>
< / tr>
< tr>
< td>
< s:textfield id =emailname =emaillabel =输入您的电子邮件/>
< / td>
< / tr>
< tr>
< td>< / td>
< td>< s:submit value =Submit/>< / td>
< / tr>
< / table>

< / s:form>

动作类

 包操作; 
import com.opensymphony.xwork2.ActionSupport;

public final class TestAction extends ActionSupport
{
private static final String SUCCESS =success;
private String name;
private String email;

public String getName(){
return name;
}

public void setName(String name){
this.name = name;
}

public String getEmail(){
return email;
}

public void setEmail(String email){
this.email = email;
}

@Override
public String execute()throws Exception
{
System.out.println(name =+ name);
System.out.println(email =+ email);
return SUCCESS;
}
}

strtus .xml file:

 <?xml version =1.0encoding = 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.enable.DynamicMethodInvocationvalue =false/>
< constant name =struts.devModevalue =true/>
< constant name =struts.custom.i18n.resourcesvalue =myapp/>

< package name =testnamespace =/ TestStrutsextends =struts-default>
< action name =testclass =actions.TestActionmethod =execute>
< result name =success> /Test.jsp< / result>
< / action>
< / package>

< / struts>

web.xml 文件:

 <?xml version =1.0encoding =UTF-8?& 
< web-app version =3.0xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/ XMLSchema-instancexsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\">
< context-param>
< param-name> contextConfigLocation< / param-name>
< param-value>
/WEB-INF/applicationContext.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>
< / filter>
< filter-mapping>
< url-pattern> / *< / url-pattern>
< / filter-mapping>

< session-config>
< session-timeout>
30
< / session-timeout>
< / session-config>
< welcome-file-list>
< welcome-file> index.jsp< / welcome-file>
< / welcome-file-list>
< / web-app>

除了Spring的jar文件,我已经将以下jar文件添加到类路径。 p>


  • commons-beanutils-1.8.0.jar

  • commons-chain-1.2.jar

  • commons-collections-3.1.jar

  • commons-digester-2.0.jar

  • commons-fileupload- jar

  • commons-io-2.2.jar

  • commons-lang3-3.1.jar

  • < lang-2.4.jar
  • commons-logging-1.1.3.jar

  • commons-logging-api-1.1.jar

  • commons-validator-1.3.1.jar

  • freemarker-2.3.19.jar

  • javassist-3.11.0。 GA.jar

  • ognl-3.0.6.jar

  • struts2-core-2.3.16.jar

  • struts2-spring-plugin-2.3.16.jar

  • xwork-core-2.3.16.jar






当URL从 .action 更改为 .jsp c $ c>像 http:// localhost:8080 / TestStruts / Test.jsp ,它会显示以下警告。

  Dec 22,2013 9:00:44 PM org.apache.struts2.components.ServletUrlRenderer warn 
警告:找不到指定操作的配置:'test'in namespace:'/ TestStruts'。表单操作默认为'action'属性的文字值。
org.apache.struts2.components.ServletUrlRenderer warn
警告:没有为指定的操作找到配置:'test'in namespace:'/ TestStruts'。表单操作默认为'action'属性的文字值。

我缺少什么?

解决方案

因为 / TestStruts 是部署您的应用程序的上下文路径。它与包中的命名空间具有相同的路径。尝试

  http:// localhost:8080 / TestStruts / TestStruts / test.action 

当URLS从struts标签呈现时,它试图找到一个相应的动作配置。如果没有找到配置,则发出警告。


I'm trying my first application on struts 2.3.16 in NetBeans 7.2.1. It shows the following error on entering a URL - http://localhost:8080/TestStruts/Test.action (There is a Test.jsp page).

WARNING: Could not find action or result: /TestStruts/Test.action
There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

The Test.jsp page:

<s:form namespace="/TestStruts" action="test">
    <table border="0" class="">
            <tr>

                <td>
                    <s:textfield id="name" name="name" label="Enter your name"/>
                </td>
            </tr>
            <tr>
                <td>
                    <s:textfield id="email" name="email" label="Enter your email"/>
                </td>
            </tr>
            <tr>
                <td></td>
                <td><s:submit value="Submit"/></td>
            </tr>
    </table>            

</s:form>

The action class:

package actions;
import com.opensymphony.xwork2.ActionSupport;

public final class TestAction extends ActionSupport
{
    private static final String SUCCESS = "success";
    private String name;
    private String email;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Override
    public String execute() throws Exception
    {
        System.out.println("name = "+name);
        System.out.println("email = "+email);
        return SUCCESS;
    }
}

The strtus.xml file:

<?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.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.custom.i18n.resources" value="myapp" />

    <package name="test" namespace="/TestStruts" extends="struts-default">
        <action name="test" class="actions.TestAction" method="execute">
            <result name="success">/Test.jsp</result>
        </action>
    </package>

</struts>

The web.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.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>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

In addition to jar files of Spring, I have added the following jar files to the classpath.

  • commons-beanutils-1.8.0.jar
  • commons-chain-1.2.jar
  • commons-collections-3.1.jar
  • commons-digester-2.0.jar
  • commons-fileupload-1.3.jar
  • commons-io-2.2.jar
  • commons-lang3-3.1.jar
  • commons-lang-2.4.jar
  • commons-logging-1.1.3.jar
  • commons-logging-api-1.1.jar
  • commons-validator-1.3.1.jar
  • freemarker-2.3.19.jar
  • javassist-3.11.0.GA.jar
  • ognl-3.0.6.jar
  • struts2-core-2.3.16.jar
  • struts2-spring-plugin-2.3.16.jar
  • xwork-core-2.3.16.jar

When the URL is changed to .jsp from .action like http://localhost:8080/TestStruts/Test.jsp, it shows the following warnings.

Dec 22, 2013 9:00:44 PM org.apache.struts2.components.ServletUrlRenderer warn
WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.
Dec 22, 2013 9:00:45 PM org.apache.struts2.components.ServletUrlRenderer warn
WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.

What am I missing?

解决方案

Because /TestStruts is a context path at which deployed your application. It has the same path as namespace in your package. Try

http://localhost:8080/TestStruts/TestStruts/test.action

When URls is rendering from the struts tags it's trying to find a corresponding action configuration. If there's no config found the warning is issued.

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

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