问题
I am using the follwoing code to rewrite my URL. everytime I click on the Profile link it works but adds EXTRA Profile/view to the end of address.
http://www.example.com/myProject/Profile/view.action
first time I click on view it changes it to
http://www.example.com/myProject/Profile/Profile/view.action
after that if I click the view again it will be (everytime I click it addes a /Profile to the address)
http://localhost:8080/myProject/Profile/Profile/Profile/view.action
link
<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>
the problem is that everytime I click on view it does not remove the address and add the profile/view to the end of it. It just change the address from www.example.com/myproject/profile/view to www.example.com/myproject/profile/profile/view
回答1:
Difficult to say without the package declaration, but it looks like you're getting an extra namespace in the action because you're specifying it in the <s:url>
tag as part of the action instead of using the namespace
attribute.
If the current action is part of the Profile namespace it won't be added. If it isn't, it will. Using the namespace
attribute handles it automatically, so you don't have to think about it.
Edited to reflect the completely unrelated question.
You are extending the struts-default
package, which has no knowledge of the tiles
result type. You need to extend your default, which does include the tiles
result type, or tiles-default
(or whatever it's called, I don't recall).
来源:https://stackoverflow.com/questions/14886855/how-to-change-my-code-to-implement-url-rewriting-correctly-using-tiles-and-strut