如果删除 Struts2 应用程序中的
.action
扩展,我会遇到问题。我把这个放在我的struts.xml
:
<constant
name="struts.action.extension"
value="" />
除了索引页面外,应用程序都可以正常工作。我的
web.xml
里有这个:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
当我访问
http://localhost/myApp/
时,出现以下错误:
There is no Action mapped for namespace [/] and
action name [index.jsp] associated with context path [/myApp].
- [unknown location]
但是,如果我访问
http://localhost/myApp/fooAction
,我不会收到任何错误并且工作正常。
如果我将扩展名更改为非空扩展名(例如
"html"
),则如果我访问http://localhost/myApp/
,我会完美地看到索引页面。
那么,我这样做有什么问题吗?为什么删除扩展程序时会出现此错误?有什么可能的办法不得到它吗?
编辑:如果我在
<welcome-page>
中放置一个操作,错误如下:
There is no Action mapped for namespace [/] and action name []
associated with context path [/myApp].
我在其中一个应用程序中遇到了同样的问题,我需要在页面加载时调用一个操作来代替
index.jsp
中的 welcom.jsp
或 <welcome-page>
。我执行了以下步骤
将以下条目放入我的 web.xml 中。
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
我在我的 web-app 文件夹中创建了一个名为
index
的空文件,最后将以下条目放入我的 struts.xml 文件中
<action name="index" class="welcomeAction">
<result>/ab.jsp</result>
</action>
所以在这种情况下,当我点击这个 URL
www.myapp.com/myApp
时,它调用 Struts2 的索引操作,我能够为我的欢迎页面完成所有初始化工作。
我也有同样的问题,但是解决了!!!!
如果你使用
<constant name="struts.action.extension" value=""/>
在struts.xml中
然后将欢迎文件设置为
<welcome-file>index.jsp</welcome-file>
在 web.xml 中
并在struts.xml中给出action如下
<package name="default" extends="struts-default">
<action name="index.jsp">
<result>WEB-INF/login.jsp</result>
</action>
</package>
我使用
websphere
运行Web应用程序,需要另外添加struts.xml,并设置<action name="">
,然后视图http://localhost:port/{context root}/
显示index.jsp
。
<package name="dst" extends="struts-default" namespace="/">
<action name="">
<result>/index.jsp</result>
</action>
</package>