struts2,Could not execute action: /newAction There is no Action mapped for action name newAction. – [unknown location]

huangapple 未分类评论54阅读模式
英文:

struts2,Could not execute action: /newAction There is no Action mapped for action name newAction. - [unknown location]

问题

>struts2,无法执行操作:/newAction。没有为操作名称newAction映射的操作。 - [位置未知]

目录和错误信息

![目录和错误信息][1]

以下是文件内容,我不知道为什么会这样。拜托了,我快要疯了。

<%--new.jsp--%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>new.jsp</title>
</head>
<body>
new
<s:action name="newAction"/>
</body>
</html>

<%-- a.jsp--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
a
</body>
</html>

<%!--struts2.xml--%>
<struts>
  <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
  <constant name="struts.devMode" value="true"/>
  <package name="homework6" extends="struts-default">
    <action name="newAction" class="homework6.action.NewAction">
      <result name="success">/a.jsp</result>
    </action>
  </package>
</struts>

//NewAction
package homework6.action;

import com.opensymphony.xwork2.ActionSupport;

public class NewAction extends ActionSupport {
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <display-name>default</display-name>
    <welcome-file-list>
        <welcome-file>new.jsp</welcome-file>
        <welcome-file>a.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>

[1]: https://i.stack.imgur.com/2y4Eh.png
英文:

>struts2,Could not execute action: /newAction There is no Action mapped for action name newAction. - [unknown location]

Directory and error information

struts2,Could not execute action: /newAction There is no Action mapped for action name newAction. – [unknown location]

Files are as follows, I do not know why it will be like that. Please, I am almost mad.

<%--new.jsp--%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>new.jsp</title>
</head>
<body>
new
<s:action name="newAction"/>
</body>
</html>
<%-- a.jsp--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
a
</body>
</html>
<%!--struts2.xml--%>
<struts>
  <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
  <constant name="struts.devMode" value="true"/>
  <package name="homework6" extends="struts-default">
    <action name="newAction" class="homework6.action.NewAction">
      <result name="success">/a.jsp</result>
    </action>
  </package>
</struts>
//NewAction
package homework6.action;

import com.opensymphony.xwork2.ActionSupport;

public class NewAction extends ActionSupport {
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <display-name>default</display-name>
    <welcome-file-list>
        <welcome-file>new.jsp</welcome-file>
        <welcome-file>a.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>

答案1

得分: 0

查看“入门”文档中的struts.xml部分

Struts 2配置文件的默认名称是struts.xml

英文:

See the struts.xml section of the "Getting Started" docs.

The default name of the Struts 2 configuration file is struts.xml.

huangapple
  • 本文由 发表于 2020年4月10日 19:49:24
  • 转载请务必保留本文链接:https://java.coder-hub.com/61139645.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定