没有为命名空间 / 和操作名称映射的操作教程

2024-03-21

我无法执行我的 struts2 应用程序。我正在使用 eclipse indigo IDE、tomcat 7 和 jdk 1.7。

我包含的 jar 文件是:

  • commons-logging-1.0.4.jar,
  • freemarker-2.3.8.jar,
  • ognl-2.6.11.jar,
  • struts2-core-2.0.11.jar,
  • xwork-2.0.4.jar

我把struts.xml在类文件夹中WEB-INF我也尝试过将其放入
src文件夹,但我无法制作它。我在控制台上收到以下错误

There is no Action mapped for namespace / and action name tutorial. - [unknown    location]

索引.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   
"http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">  
    <title>Insert title here</title>  
</head>  
<body>  
    <form action="./tutorial.action">  
        Username: <input type="text" />  
        <input type="submit" value="Submit" />  
    </form>  
</body>  
</html>  

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" extends="struts-default">
        <action name="tutorial" class="com.test.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/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"   
xmlns:web="http://java.sun.com/xml/ns/javaee/web-
app_2_5.xsd" 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>Struts2Starter</display-name>
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

教程操作.java

package com.test;   

public class TutorialAction {   
    public String execute() {
        System.out.println("Hello from execute");   
        return "success";   
    }
}

正如其他人指出的那样,您的映射中没有 getTutorial 操作,只有“教程”。不过,我将跳过这一点并建议您学习如何对 Struts2 应用程序进行健全性检查。任何时候您正在设置一项新技术,甚至当您使用熟悉的技术时,了解如何进行基本的健全性检查都是非常有用的——在这种情况下,您需要验证您的 struts xml 是否已成功完成已解析并且框架知道您的操作。

我强烈建议您添加Struts 2 配置浏览器插件 http://struts.apache.org/2.3.4.1/docs/config-browser-plugin.html到您的 struts 2 应用程序。要添加插件,您只需拿到罐子 http://search.maven.org/#search%7Cgav%7C1%7Cg%3a%22org.apache.struts%22%20AND%20a%3a%22struts2-config-browser-plugin%22(所有 struts 2 插件都是 jar )并放入 web 应用程序的 lib 目录中。就是这样。当您启动应用程序时,请点击以下 URL:

http://localhost:8080/starter/config-browser/index.action

它向您显示框架了解的所有操作以及其他配置。 Essentialy struts 2 诊断工具,太容易使用了,无法不使用它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

没有为命名空间 / 和操作名称映射的操作教程 的相关文章

随机推荐