我收到以下错误,我搜索了很多并获得了许多不同类型的解决方案,但无法解决它。
我的Stacktrace
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";
}
}
Welcome.jsp中
<p>done</p>
的Login.jsp
<p>not done</p>
我已经创建了这个项目来学习Struts,所以只想看看struts.xml到action类的映射是怎么做的
我成功运行localhost:8080 / TicketSystem / index.html 但是当我运行localhost:8080 / TicketSystem / CreateTicket.action时。我收到了上述错误..
请帮我解决。
此致 马赫什
答案 0 :(得分:1)
我认为这是因为你没有定义命名空间。
试试这个。
<package name="default" namespace="/" extends="struts-default">
答案 1 :(得分:0)
我收到此错误的原因是我的构建路径。我的构建路径设置为不在WEB-INF
类的其他目录。做这个改变,解决了我的问题。
答案 2 :(得分: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>
所以,如果以这种方式执行此操作,只需确保必须通过Action名称从jsp调用操作,只需要编写将导致错误的.action。这可能是你问题的理想答案。
我相信这会奏效。