没有为名称空间/和操作名称教程映射的操作 [英] There is no Action mapped for namespace / and action name tutorial
问题描述
我无法执行我的struts2应用程序.我正在使用Eclipse Indigo IDE,tomcat 7和jdk 1.7.
I am unable to execute my struts2 application. I am using eclipse indigo IDE, tomcat 7 and jdk 1.7.
我包含的jar文件是:
The jar files I included are:
- 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
的classes文件夹中,我也尝试将其放置在
src
文件夹,但我无法做到.我在控制台上收到以下错误
I placed the struts.xml
in classes folder in WEB-INF
and I also tried it placing in
src
folder but I could not able to make it. I am getting the below error on console
There is no Action mapped for namespace / and action name tutorial. - [unknown location]
index.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>
TutorialAction.java
package com.test;
public class TutorialAction {
public String execute() {
System.out.println("Hello from execute");
return "success";
}
}
推荐答案
正如其他人指出的那样,映射中没有getTutorial动作,只有"tutorial".但是,我将跳过这一点,建议您学习如何理智检查Struts2应用程序.每当您设置新技术时,甚至当您使用熟悉的技术时,了解如何进行基本的健全性检查也非常有用-在这种情况下,您需要验证struts xml是否已成功解析,并且框架知道您的操作.
As others have pointed out, you do not have a getTutorial action in your mapping, only a "tutorial". However, I'm going to skip over that and suggest that you learn how to sanity check a Struts2 app. Anytime you are setting up a new technology, and even when you are working with a familiar technology, it is very useful to understand how to do a basic sanity check -- in this case, you need to verify that your struts xml has been successfully parsed and the framework knows about your actions.
我强烈建议您添加 Struts 2 Config Browser插件到您的struts 2应用程序.要添加插件,您只需
I HIGHLY RECOMMEND you add the Struts 2 Config Browser plugin to your struts 2 apps. To add the plugin, you just get the jar ( all struts 2 plugins are jars ) and put in your webapp's lib directory. That's it. When you start your applicaiton, hit this URL:
http://localhost:8080/starter/config-browser/index.action
它向您显示了框架知道的所有动作以及其他配置. Essentialy struts 2诊断工具,太容易使用了,无法使用.
And it shows you all of the actions, as well as other configurations, that the framework knows about. Essentialy struts 2 diagnostic tool, and too easy to use to not use it.
这篇关于没有为名称空间/和操作名称教程映射的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!