`

警告: No configuration found for the specified action(转)

阅读更多
警告信息:

警告: No configuration found for the specified action: '/myNameSpace/login.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

struts.xml配置信息(部分)

<package name="packageName" extends="struts-default" namespace="/myNameSpace">
    <action name="login" class="com.jato.srvclink.test.login.LoginAction" method="login">

jsp页面配置信息(部分)

<s:form action="/myNameSpace/login.action">

思考:没有在''的namespace中发现指定的action '/myNameSpace/login.action'
答疑:因为配置的struts2标签并未指定namespace属性。所以struts2会默认从根命名空间"/"搜索action串'/myNameSpace/login.action',如果搜索不到将进入默认命名空间''搜索action请求串,在默认命名空间中是肯定找不到我们定义的action的,所以,struts2抛出一个警告信息。
但是为什么我们没有填写namespace,我们的请求也可以正常访问呢?

我们来看一下解析后的html
查看源码得到的html(部分)

<form id="login" onsubmit="return true;" action="/srvclink/myNameSpace/login.action" method="post">

我们看到form提交的action串是准确的url请求,action串确实是/srvclin(应用根)/myNameSpace(命名空间)/login.action。
命名空间中找不到action定义,并不意味着这个action真的不存在,只是我们的代码有问题而已。还有一点是我们在jsp页面的action请求中手动的加入了.action后缀。事实上struts2会自动追加.action的,因为我们并没有合法的使用struts2的标签,所以struts2这里并没有给我们追加.action,解析后的代码中存在的.action,完全是我们手动在jsp页面填写的,有疑问的网友可以不手动添加查看html。

我们修改我们的程序代码

jsp页面配置信息(部分)修改后加入namespace属性,修改action属性值为/login.action

<s:form action="/login.action" namespace="/myNameSpace">

请求页面后,大家很失望吧?警告依然存在。但是我们看一下警告信息。

警告信息:

警告: No configuration found for the specified action: '/login.action' in namespace: '/myNameSpace'. Form action defaulting to 'action' attribute's literal value.

没有在'/myNameSpace'的namespace中发现指定的action '/login.action'

毫无疑问,这里的警告和第一次的警告信息截然不同。我们现在存在命名空间,'/myNameSpace'能够被struts2检索到,并不是开始的''。那问题的关键在哪里呢?
在namespace中没有发现指定的action '/login.action' ???

我们来看一下struts.xml中的配置:

struts.xml配置信息(部分)

<package name="packageName" extends="struts-default" namespace="/myNameSpace">
    <action name="login" class="com.jato.srvclink.test.login.LoginAction" method="login">

是的,我们'/myNameSpace'命名空间下,只有action名字为'login'的定义,并没有所谓的 '/login.action' 定义,所以struts2的警告并未错。如果大家对这个抱有怀疑,可以修改action的名字'login'为‘/longin.action’
<action name="/login.action" class="com.jato.srvclink.test.login.LoginAction" method="login">
请求页面时你会发现不在报警告信息,原因很简单。因为在命名空间为'myNameSpace'下确实存在命名为'/login.action'的action。

我们再次修改配置文件

jsp页面配置信息(部分)修改后action属性值为longin

<s:form action="login" namespace="/myNameSpace">

请求页面时,我们发现不再有警告信息了。

如果你有足够细心,我想你应该可以彻底的明白为什么struts2会报警了吧?你也应该明白了使用struts2标签action中添加/线后请求反而报错的原因了。
(转自:http://hi.baidu.com/mum0532/blog/item/128f9a64fa8594f5f6365457.html)
1
0
分享到:
评论

相关推荐

    Java邮件开发Fundamentals of the JavaMail API

    things like the last mail received and calculate how many are new for you. So, when using the JavaMail API, if you want this type of information, you have to calculate it yourself. IMAP IMAP is a...

    BURNINTEST--硬件检测工具

    - Minor changes to the No operation error watchdog timer for the CD and Hard disk tests. - Minor correction to the Butterfly seek test. - Video playback trace logging increased. Release 5.3 build ...

    OutlookAttachView v2.73

    o Added option to scan only emails with the specified 'From' and 'To' strings. * Version 1.82 o When adding a folder to scan (with the Add button), the folder path in now delimited with quotes, ...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    For this reason, the functions that handle these actions offer the option of waiting until the action is complete before returning (so-called synchronous operation); although they can be called in an ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    is now available for writing (during the writing, the standard grid object TFlexGrid is released, and a user's one is set). - ADD: In the class TFlexGrid added the properties HOffset and VOffset - ...

    Turbo C 2.00[DISK]

    When /P is specified, the EGA palette will be restored each time the screen is swapped. In general, you don't need to use this switch unless your program modifies the EGA palette registers, or ...

    Turbo C 2.01[DISK]

    When /P is specified, the EGA palette will be restored each time the screen is swapped. In general, you don't need to use this switch unless your program modifies the EGA palette registers, or ...

    CE中文版-启点CE过NP中文.exe

    Fixed the found code dialog count size Fixed mono freezing Cheat Engine when it crashes/freezes Additions and changes: Changed the processlist and added an Applications view similar to the ...

    php.ini-development

    Please see the actual settings later in the document for more details as to why ; we recommend these changes in PHP's behavior. ; display_errors ; Default Value: On ; Development Value: On ; ...

    DebuggingWithGDB 6.8-2008

    4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

Global site tag (gtag.js) - Google Analytics