如何忽略 struts2 中的默认命名空间

how to ignore default namespace in struts2

各位。 我在 struts2 命名空间上遇到问题..

首先,这是我的开发环境。 服务器:tomcat (目前我的项目在 /tomcat/webapps/ROOT 中的 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="/" 用于默认命名空间...

问题:

  1. 有没有忽略默认命名空间的方法?因为我想使用那个 / 因为我只想遍历 http://.../ 和没有命名空间的动作名称...

  2. 或者如果没有办法做到这一点。有什么建议吗?

  1. 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 属性,则会使用它。


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