0

我收到以下错误,我用谷歌搜索了很多,得到了许多不同类型的解决方案,但无法解决。

我的堆栈跟踪

    SEVERE: Could not find action or result
There is no Action mapped for namespace / and action name CreateTicket. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
    at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
    at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
    at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
    at java.lang.Thread.run(Thread.java:595)

我的 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" />
    <constant name="struts.multipart.maxSize" value="20480000" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />

    <package name="default" extends="struts-default">
        <action name="CreateTicket" class="com.ticketservice.CreateTicket">
            <result name="success">Welcome.jsp</result>
            <result name="error">Login.jsp</result>
        </action>


    </package>
</struts> 

我的目录结构

在此处输入图像描述

CreateTicket.java

package com.ticketservice;

import com.opensymphony.xwork2.ActionSupport;

public class CreateTicket extends ActionSupport {

    public String execute() {

       return "success";
    }
}

欢迎.jsp

<p>done</p>

登录.jsp

<p>not done</p>

我创建了这个项目来学习 Struts,所以只想看看 struts.xml 到动作类的映射是如何完成的

我能够成功运行 localhost:8080/TicketSystem/index.html。
但是当我运行 localhost:8080/TicketSystem/CreateTicket.action 时。我得到了上述错误..

请帮我解决它。

问候, 马赫什

4

3 回答 3

1

我认为这是因为您尚未定义名称空间。

尝试这个。

<package name="default" namespace="/" extends="struts-default">

于 2012-12-11T06:11:10.150 回答
0

The reason I was getting this error was my build path. My build path was set to other directory not at WEB-INF classes. Doing this change, solved my problem.

于 2012-12-13T09:05:23.113 回答
0

可能是您在 struts.xml 文件中犯了错误。所以这里有几种配置xml文件的方法。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
    <package name="default" extends="struts-default">
        <action name="helloWorld" class="controller.HelloWorld">
            <result name="success">/HelloWorld.jsp</result>

        </action>
    </package>
</struts>    

因此,如果您以这种方式执行此操作,只需确保您必须通过操作名称从 jsp 调用操作,您不需要编写会导致错误的 .action。这可能是您问题的理想答案。

我相信这会奏效。

于 2013-10-14T08:15:28.057 回答