Form action defaulting to 'action' attribute's literal value .
2016-03-10 16:05
471 查看
在使用<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。
转载请注明 historycreator.com
警告信息内容如下:
警告: 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。
转载请注明 historycreator.com
相关文章推荐
- 远程调用服务(RPC)和消息(Message Queue)对比及其适用/不适用场合
- Druid连接池 一个设置 removeAbandonedTimeout
- Querydsl
- java序列化和serialVersionUID 总结
- Google guice
- common,Google Guava,Guice
- Lucene--FuzzyQuery与WildCardQuery(通配符)
- ConcurrentLinkedQueue
- ArrayBlockingQueue、LinkedBlockingQueue、ConcurrentLinkedQueue
- 字符集编码插入Mysql数据库是,字符utf8编码超过3位时的错误以及解决,Incorrect string value: '\xF0\xA1\xBF\xA8\
- LinkedBlockingQueue和ConcurrentLinkedQueue
- lucene4.7 正则查询(RegexpQuery)(八)
- Exception in thread &quot;AWT-EventQueue-0&quot; java.awt.HeadlessException:
- 数据库参考,键值(Key-value)数据库,列式存储,文档型数据库,图型数据库
- Storm UI
- 使用SoapUI 测试Web Service
- activemq 控制面板里的 Number Of Pending Messages、 Messages Enqueued、Messages Dequeued含
- 错误The request sent by the client was syntactically incorrect ()的解决
- java Queue
- 蓝牙基础知识进阶——物理链路和逻辑传输