每个人。
我在 struts2 命名空间上遇到了问题..
首先,这是我的开发环境。
服务器:tomcat
(目前我的项目在 ROOT
文件夹中 /tomcat/webapps/ROOT
)
框架:struts2
这是我的问题。
假设有两页。 admin_index.jsp 和 front_index.jsp
当我想从操作中调用 admin_index.jsp 时。我用
<package name="admin" namespace="/dl_adm" extends="struts-default">
<action name="/index" method="index"class="kr.co.www2.controller.front.AdminMainController">
<result name="success">/WEB-INF/jsp/admin/admin_index.jsp</result>
</action>
</package>
通过调用
http://.../dl_adm/index.do
可以正常工作并称这对我来说有问题。
<package name="front" namespace="/" extends="struts-default">
<action name="/index" method="index"class="kr.co.www2.controller.front.FrontMainController">
<result name="success">/WEB-INF/jsp/admin/front_index.jsp</result>
</action>
</package>
当我去找
http://.../index.do
,它给出了 404...虽然我知道
namespace="/"
用于默认命名空间...问题:
/
因为我只想通过http://.../
和没有命名空间的操作名称... 最佳答案
- Is there anyway to ignore the default namespace? because i want to use that / because i just want to go through
http://.../
and action name without namespace..
不,您不能忽略默认命名空间。默认命名空间为空,如果省略
namespace
则使用它包声明中的属性。
- or if there isnt a way to do that. any suggestions?
我不会使用 xml 配置在操作名称中使用斜杠。操作映射器可能会错误地向操作名称添加额外的斜杠以从 URL 推断映射。
所以你应该使用
<package name="front" namespace="/" extends="struts-default">
<action name="index" method="index"class="kr.co.www2.controller.front.FrontMainController">
<result name="success">/WEB-INF/jsp/admin/front_index.jsp</result>
</action>
</package>
关于struts2 - 如何忽略struts2中的默认命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45325812/