问题描述
错误: 没有为与上下文路径[/ Struts2Test]关联的名称空间[/]和操作名称[testAction]映射的操作。
struts.xml
window
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="test" extends="struts-default">
<action name="testAction" class="com.velox.test.TestAction" method="execute">
<result name="success">/Success.jsp</result>
<result name="error">/Error.jsp</result>
</action>
</package>
</struts>
TestAction.java
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>Struts2Test</display-name>
<welcome-file-list>
<welcome-file>index.html</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.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Success.jsp
package com.velox.test;
public class TestAction {
public String execute() {
System.out.println("execute() method called");
return "success";
}
}
Error.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<Meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Success Page</h1>
</body>
</html>
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<Meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Error Page</h1>
</body>
</html>
输出 [运行项目] [1] [点击testAction URL] [2] [1]:https://i.stack.imgur.com/YiXA1.png [2]:https://i.stack.imgur.com/R2e5k.png
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)