微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何更改我的代码以使用tile和struts2正确实现url重写

如何解决如何更改我的代码以使用tile和struts2正确实现url重写

没有包声明就很难说,但是看起来您在操作中获得了一个额外的名称空间,因为您是在<s:url>标签中将其指定为操作的一部分,而不是使用namespace属性

如果当前操作是Profile命名空间的一部分,则不会添加。如果不是,它将。使用namespace属性自动处理它,因此您不必考虑它。

编辑以反映完全无关的问题。

您正在扩展struts-default不知道tiles结果类型的程序包。你需要延长 你的 认,这 包括tiles结果类型,或tiles-default(或任何它的名字,我不记得)。

解决方法

我正在使用下面的代码重写我的URL。每次我点击“个人资料”链接时,它都会起作用,但会将EXTRA个人资料/视图添加到地址末尾。

http://www.example.com/myProject/Profile/view.action

第一次单击查看时,它将更改为

 http://www.example.com/myProject/Profile/Profile/view.action

之后,如果我再次单击该视图,它将是(每次单击该视图都会在该地址中添加一个/ Profile)

  http://localhost:8080/myProject/Profile/Profile/Profile/view.action

链接

  <a href="<s:url action="Profile/view"/>" >Profile</a>

struts.xml

   <package name="default" extends="struts-default">
    <result-types>
        <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
    </result-types>

      <action name="index">
        <result type="tiles">content</result>
    </action>

 </package>

  <package name="Profile" extends="default" namespace="/Profile">
  <action name = "*" method="{1}" class="com.myproject.Profile">
    <result name="View" type="tiles">Profile</result>
            <result name="Edit" type="tiles">Edit</result>
</action>
    </package>

问题是,每次我单击视图时,它都不会删除地址并将配置文件/视图添加到其末尾。
只需将地址从www.example.com/myproject/profile/view更改为www.example.com/myproject/profile/profile/view

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。