0

I want to rewrite my URL in Struts2.

How can I customize URL which shouldn't show my parameter that I am passing and also show action with different name.

I don't know how to do it. I have to use plugins for that or configure my code in struts.xml:

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.action.extension" value="action" />
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="true" />
    <constant name="struts.ui.theme" value="simple" />  
    
    
    <include file="struts-user.xml"></include>
    <include file="struts-admin.xml"></include>
    <include file="struts-common.xml"></include>
    <include file="struts-masters.xml"></include>
</struts>

Tell me the way how to perform as well as give me a solution.

My URL is like this:

/operations/MatchPredictionLevel2_index.action?sgt=102&lvl2=1&tn=MatchPredictionLevel2

I want to show my URL like

/operations/prediction 

to the user and the same thing I want to do for all URLs based on its purpose.

Roman C
  • 49,761
  • 33
  • 66
  • 176
CHiRAG
  • 222
  • 4
  • 15

1 Answers1

0

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>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • currently i am using wildcard mapping but it shows the actipn name like insert update etc... you have any demo of Tuckey URL rewriting?. – CHiRAG Aug 12 '14 at 09:42
  • i have seen your updated answer, but with out its explanation its dfficult to use the tag which we are use and the parameter of tag ^/(.*)$ – CHiRAG Aug 13 '14 at 04:32
  • 1
    I have given you an answer, however your question is too broad. You should follow the links to get explanation you want or edit your question and highlight details by asking concrete question. – Roman C Aug 13 '14 at 10:06
  • Roman C can you give my recent question answer about struts parameter passing in XML – CHiRAG Aug 13 '14 at 10:13
  • First we need to do something to this question, also I don't understand your comment about parameter of tag. – Roman C Aug 13 '14 at 16:29
  • Roman it is my different question that i ask, it is not related to `URL rewriting`. It is about Parameter passing in `Struts.xml` file. I have asked question separately if u help me in this. – CHiRAG Aug 14 '14 at 04:53