首页 > 解决方案 > struts2,Could not execute action: /newAction 没有为动作名称newAction映射的动作。- [未知位置]

问题描述

struts2,Could not execute action: /newAction 没有为动作名称newAction映射的动作。- [未知位置]

目录和错误信息

目录和错误信息

文件如下,不知道为什么会这样。拜托,我快疯了。

<%--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>

标签: javastruts2

解决方案


请参阅“入门”文档的struts.xml 部分。

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


推荐阅读