解决:No configuration found for the specified action

el/2024/2/25 23:45:39

原文地址:http://javasunnyboy.iteye.com/blog/254753

今天首次使用Struts2,配置一切正常,使用常用tag也正常,但是在使用<s:form>标记时,发现控制台总是输出警告信息, 


警告信息内容如下: 

警告: No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value. 
2008-9-6 11:35:47 org.apache.struts2.components.Form evaluateExtraParamsServletRequest 
警告: No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value. 

showmsg.jsp代码如下 

<%@ taglib prefix="s" uri="/struts-tags" %> 
...... 
<div> 
hello world 
<s:form name="ShowMessage" method="post" action="/hello/ShowMessage.action" > 
<s:textfield label="user name" name="username"></s:textfield> 
<s:submit></s:submit> 
</s:form> 
</div> 
...... 

struts.xml配置如下: 
...... 
<struts> 
<package name="hello" extends="struts-default" namespace="/hello"> 
<action name="ShowMessage" class="com.historycreator.strutstest.ShowMessage"> 
<result>/digg/showmsg.jsp</result> 
</action> 
</package> 
</struts> 

打开showmsg.jsp页面时,就出现上述异常。尝试了各种配置和访问方法,均出现警告。搜索网络给出的答案几乎都说把<s:form name="ShowMessage" method="post" action="/hello/ShowMessage.action" >中的.action去掉就可以解决了,做了测试,问题仍然没有解决。更有人让把<s:去掉,不用tag,直接写<form>这个当然不会有问题,但是一会用标记,一会不用,很杂乱,并且不是解决问题的根本之道。 

解决方法: 
经过测试发现,是没有正确使用tag的原因,这种情况下,正确的写法应该是,<s:form name="ShowMessage" method="post" action="ShowMessage" namespace="/hello" > 


原因分析: 

因为开始使用的struts2标签(form)并未指定namespace属性。所以struts2会默认从根命名空间"/" 搜索action '/hello/ShowMessage.action',如搜索不到则进入默认命名空间''搜索action串,在默认命名空间中是肯定找不到自己定义的action的,所以,struts2抛出一个警告信息。 

现在我们指定了namespace为/hello,则struts2会直接在/hello命名空间寻找。可以想象,如果在这么命名空间里找不到请求的action,也会抛出一条类似的信息。 

注意,<s:form name="ShowMessage" method="post" action="ShowMessage" namespace="/hello" > 
不能写成<s:form name="ShowMessage" method="post" action="ShowMessage.action" namespace="/hello" > 

这样仍然有对应的警告信息,并且提交后出现无法访问的结果。因为没有ShowMessage.action这样一个action,这个.action不能由我们手工添加,Struts2会自动为你完成这个工作,并且手工添加是不行的,就不必多此一举了。但是在其他的场合,比如使用超级链结,则可以加上这个.action。 

http://www.ngui.cc/el/4465812.html

相关文章

android模拟器访问本地站点

原文地址&#xff1a;http://weizhulin.blog.51cto.com/1556324/311704

Struts2常量详解

原文地址&#xff1a;http://riddickbryant.iteye.com/blog/557373 通常struts2加载struts2常量的顺序如下: 1. struts-default.xml&#xff1a;该文件保存在struts2-core-2.0.6.jar文件中。 2. struts-plugin.xml&#xff1a;该文件保存在struts2-Xxx-2.0.6.jar等Struts2插件J…

Spring依赖注入例子

从Spring手册中摘录的一段&#xff0c;有关依赖注入的例子 The following example uses XML-based configuration metadata for setter-based DI. A small part of a Spring XML configuration file specifies some bean definitions: <bean id"exampleBean" clas…

Twitter的禁用口令

原文地址&#xff1a;http://coolshell.cn/articles/2451.html 打开Twitter的注册页面&#xff0c;https://twitter.com/signup&#xff0c;查看一下源码&#xff0c;你会看到一个很长的禁用口令列表&#xff08;见本文最下面&#xff09;&#xff0c;其中的某些口令的确很雷人…

使用库org.json 和 Gson 解析 JSON格式字符串

org.json库为JSON创始人编写的解析JSON的java库&#xff0c;Gson为Google为我们提供的解析JSON格式数据的库。有关库内容的的下载参见&#xff1a;http://www.json.org 以下是两个简单的测试程序 使用Gson库&#xff1a; public class User {String username;String password;p…

Programs as Data: Function Pointers(函数指针)

原文链接&#xff1a;http://www.cprogramming.com/tutorial/function-pointers.html A function pointer is a variable that stores the address of a function that can later be called through that function pointer. This is useful because functions encapsulate beh…

Improved Type Inference in C++11: auto, decltype, and the new function declaration syntax

原文链接地址&#xff1a;http://www.cprogramming.com/c11/c11-auto-decltype-return-value-after-function.html Note: C11 is the now offical name for the next version of the C standard, previously known as C0x. C11 introduces several new handy-dandy type in…

C++0x: The future of C++

原文链接http://www.cprogramming.com/c11/what-is-c0x.html What is C0x? C0x is the working name for the new standard for C, adding many language features that Ill cover in this series on C0x. Just days ago, a C0x draft was voted on and finalized, meaning…

Work with dates and times(C和C++程序设计中使用日期和时间)

原文链接&#xff1a;http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer1048383636&id1043284392&utm_sourcenewletter&utm_mediumemail&utm_campaignfiftyeighth-followup C and C offer extensive date and time manipulation functions in the &l…

What's the difference between declaring and defining something in C and C++?(C和C++中,声明和定义的区别)

原文地址&#xff1a;http://www.cprogramming.com/declare_vs_define.html In C and C, there is a subtle(细微的) but important distinction between the meaning of the words declare and define. If you dont understand the difference, youll run into weird linker …