How to wtite pretty URL in Struts2.x?

◇◆丶佛笑我妖孽 提交于 2019-12-01 14:01:25

If you don't want to show the parameter passing you could use this solution.

To hide passed parameter actually you need to submit the form. You should prevent the default behavior of the click event and replace it with the form event.

If you also want to show action with different name, you can use the above filter or wildcard mapping.

Advanced Wildcards

From 2.1.9+ regular expressions can be defined defined in the action name. To use this form of wild card, the following constants must be set:

<constant name="struts.enable.SlashesInActionNames" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.patternMatcher" value="regex" />

The regular expressions can be in two forms, the simplest one is {FIELD_NAME}, in which case the field with the FIELD_NAME in the action will be populated with the matched text, for example:

<package name="books" extends="struts-default" namespace="/">
    <action name="/{type}/content/{title}" class="example.BookAction">
  <result>/books/content.jsp</result>
    </action>
</package>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!