`

警告: No configuration found for the specified action: '/myNameSpace/login.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中的配置:
<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中添加/线后请求反而报错的原因了。
分享到:
评论

相关推荐

    warning ..\package.json: No license field

    在初始化Vue项目的的时候发现警告 yarn install 查了下发现是,package.json 文件中缺少license参数 { name: movie_view, version: 0.1.0, license: MIT, private: true, scripts: { serve: vue-cli-...

    Rational Interger

    Rational Interger

    Web Navigation

    VISIT : Push the current page on the top of the backward stack, and make the URL specified the new current page. The forward stack is emptied. QUIT: Quit the browser. Assume that the browser ...

    squashfs1.3r3.tar.gz

    or ./) the entry is treated as absolute, however, if an exclude file/directory is relative, it is treated as being relative to each of the sources in turn, i.e. %mksquashfs /tmp/source1 source2 ...

    最快捷的IP备份工具

    For Release and Renew, if no adapter name is specified, then the IP address leases for all adapters bound to TCP/IP will be released or renewed. For Setclassid, if no ClassId is specified, then ...

    EurekaLog_7.5.0.0_Enterprise

    17)..Added: Support for relative file paths and environment variables for events and various module paths 18)..Added: Logging in Manage tool 19)..Added: Windows 10 version detection 20)..Added: Stack ...

    EEUPDATE刷MAC工具 EEUPDATE v5.30.10.00

    Selects all adapters found in the system. /NIC=XX Selects a specific adapter (1-32). /BUS=XX Selects PCI bus of adapter to program. Must be used with the DEV parameter to specify an adapter. /...

    LINUX gd-2.0.35.tar.gz

    If the DIR argument is specified, configure tries to find the png header files in DIR/include, and the libraries in DIR/lib. To accommodate OpenBSD ports, DIR/include/libpng is also checked if ...

    yaffs_vfs.c, android

    fs/yaffs2/yaffs_vfs.c:2390:2: error: unknown field 'get_sb' specified in initializer fs/yaffs2/yaffs_vfs.c:2390:2: warning: initialization makes integer from pointer without a cast fs/yaffs2/yaffs_vfs...

    UE(官方下载)

    You can use these functions to insert a file into the current file, delete the active file, send the file through email, or insert a string into the file at every specified increment HTML preview ...

    tensorflow-1.12支持cuda10.0

    Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]: Not configuring the WORKSPACE for Android builds. Preconfigured Bazel build configs. You can use any of the below by ...

    google api php client

    The method used is a matter of preference, but *it will be very difficult to use this library without first understanding the JSON syntax for the API*, so it is recommended to look at the [APIs ...

    MyBase Desktop 6.0.2 破解正式版(官方更新至10/10/2011)

    8.Added: the 'Organize' menu onto the main menu, as many users can't find the 'Sort child items' utility, which is also located in the 'Outline' action menu. 9.Added: Alt-Drag to create symbolic links...

    apktool documentation

    // builds current directory into ./dist $ apktool b bar -o new_bar.apk // builds bar folder into new_bar.apk $ apktool b bar.apk // WRONG: brut.androlib.AndrolibException: brut.directory....

    nao机器人java语音源码

    /// Performs the text-to-speech operations: it takes a std::string as input and outputs the corresponding audio signal in the specified file. /// &lt;/summary&gt; /// &lt;param name="pStringToSay"&gt; Text to ...

    CrashSenderexe.zip

    报错crashsender.exe is not found the specified path

    关于IllegalStateException: The specified child already has a parent.

    IllegalStateException: The specified child already has a parent.我的博客中有文章讲解

    STG (SNMP Traffic Grapher)

    You may charge a fee for the physical act of transferring a copy only. This program is distributed WITHOUT ANY WARRANTY. Use it at your own risk. I cannot guarantee accuracy of displayed data. I...

    postgresql缺少文件

    问题链接:https://blog.csdn.net/u011043673/article/details/103099092 在 postgresql 加载timescaledb 时报:could not load library timescaledb-1.4.2.dll The specified procedure could not be found.

    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 ; ...

Global site tag (gtag.js) - Google Analytics