尝试更改struts.xml
的位置但仍然出错。此外,名称空间正在URL中使用,但仍然会收到错误。
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>
<package name="default" namespace="/program" extends="struts-default">
<action name="getTwo" class="StrutsTwopack.ProgramTwo">
<result>/success.jsp </result>
<result>/failure.jsp</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>StrutsStart</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
动作类:
package ninad.Struts2One;
import service.ProgramBest;
public class ProgramOneAction {
private String bestprog;
private String Lang;
public String execute()
{
ProgramBest pb = new ProgramBest();
setBestprog(pb.giveBestProgram(getLang()));
System.out.println(bestprog);
//System.out.println(getLang());
return "success";
}
public String getBestprog() {
return bestprog;
}
public void setBestprog(String bestprog) {
this.bestprog = bestprog;
}
public String getLang() {
return Lang;
}
public void setLang(String Lang) {
this.Lang = Lang;
}
}
服务类:
package service;
public class ProgramBest {
public String giveBestProgram(String lang) {
if (lang.equals("java")){
return "My code";
}
else
return "no other code";
}
}
我在Apache窗口中输入的URL是:
http://localhost:8484/StrutsStart/program/ProgramOne.action
我得到的错误是:
There is no Action mapped for action name ProgramOne. - [unknown location]
答案 0 :(得分:0)
您已发布问题
'struts2
中没有为动作名称getTwo映射的动作
行动getTwo
已映射到名称空间StrutsTwopack.ProgramTwo
中的类/program
。如果错误为true,则表示类错误或URL中的命名空间错误。
我该怎么办?
发布SSCCE,或自行决定哪个错误版本可以更好地解析。