尝试更改位置,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]