如果我删除struts2 .action扩展名,为什么welcome-file-list不起作用? [英] Why welcome-file-list is not working if I remove struts2 .action extension?
问题描述
如果我在Struts2应用程序中删除 .action
扩展名,则会出现问题。我把它放在我的 struts.xml
中:
I have a problem if I remove the .action
extension inside my Struts2 application. I put this in my struts.xml
:
<constant
name="struts.action.extension"
value="" />
除索引页面外,应用程序正常工作。我有 web.xml
这个:
The application works correctly except in the index page. I have in my web.xml
this:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
当我访问 http:// localhost / myApp /
,我收到以下错误:
When I access to http://localhost/myApp/
, I get the following error:
There is no Action mapped for namespace [/] and
action name [index.jsp] associated with context path [/myApp].
- [unknown location]
但是,如果我访问 http :// localhost / myApp / fooAction
,我没有收到任何错误并且工作正常。
However if I access to http://localhost/myApp/fooAction
, I'm not getting any errors and works perfectly.
如果我更改非扩展名空扩展(如html
),如果我访问 http:// localhost / myApp / $ c,我会完全看到索引页面$ c>。
If I change the extension for a non empty extension (like "html"
), I see the index page perfectly if I access to http://localhost/myApp/
.
那么,我正在做的事情有什么不对吗?删除扩展程序时,为什么会出现此错误?有没有可行的方法没有得到它?
So then, is there something wrong in what I'm doing? Why am I getting this error when I remove extension? Is there any posible way of not getting it?
编辑:如果我在< welcome中放置了一个动作-page>
错误如下:
There is no Action mapped for namespace [/] and action name []
associated with context path [/myApp].
推荐答案
我在其中一个应用程序中遇到了同样的问题我需要在页面加载时调用Action来代替 index.jsp
或 welcom.jsp
in < welcome-page>
。我做了以下步骤
I was having same issue in one of the application where i need to call an Action on page load in place of index.jsp
or welcom.jsp
in <welcome-page>
.I did the following steps
在我的web.xml中放置以下条目。
Placed the following entry in my web.xml.
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
我创建了一个名为 index
的空文件在我的web-app文件夹中,最后将以下条目放在我的struts.xml文件中
I created an empty file with name index
in my web-app folder and finally placed the following entry in my struts.xml file
<action name="index" class="welcomeAction">
<result>/ab.jsp</result>
</action>
所以在这种情况下,当我点击这个URL www.myapp.com / myApp
,它的Struts2调用索引操作和我能够为我的欢迎页面完成所有初始化工作。
So in this case when i was hitting this URL www.myapp.com/myApp
,its calling index action of Struts2 and i was able to do all init work for my welcome page.
这篇关于如果我删除struts2 .action扩展名,为什么welcome-file-list不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!