5

I've been learning to use struts2 rest plugin from a past few days. But no-where I found how to map long rest URLs.

For e.g. If I want to map an URL like below :

/profiles/user-test/orders/64/item/4

where

username is user-test
order id is 64
item id is 4

How can I map something like this to a struts2 action ?

All I found on internet is just a single level being edited/displayed etc. But if I want to display something on multiple-level - then how to proceed ? Please guide.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
coding_idiot
  • 13,526
  • 10
  • 65
  • 116

1 Answers1

5

You can do it with Advanced Wildcard Mappings, without the REST plugin:

/profiles/user-test/orders/64/item/4

username is user-test

order id is 64

item id is 4

The action configuration needed for this example would be:

<action name="/profiles/{username}/orders/{order}/item/{item}" class="fooBarAction">
    <result>fooBar.jsp</result>
</action>
Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • 1
    it worked!!.. sorry for the late reply, I was having university exams. – coding_idiot May 21 '13 at 04:03
  • Although it doesn't work straight forward, I had to use regex to prevent username to span complete url after profiles/ and similarly, I used regex with other {named} variables. – coding_idiot May 21 '13 at 04:09
  • 2
    Then answer your own question if you want, to help future visitors :) – Andrea Ligios May 21 '13 at 07:28
  • So the Struts2 REST plugin is only useful with single level URLs? :( . Thanks for this answer, I'll try it out also. – orique Jul 19 '13 at 08:09
  • This kind of mapping doesn't work while using with REST API. I mean, if there're actions/controllers say, `movies` `actors` `reviews` and to check the `actors` or `reviews` of a particular `movie` we would be having the URL like `movies/{movie_id}/actors/{actor_id}` or `movies/{movie_id}/reviews/{review_id}`. But since 'moves` `actors` `reviews` are itself actions, it's not working the way we intend... Not sure why, its so. Can anyone please look into this question? https://stackoverflow.com/questions/71044199/struts2-wildcard-mapping-not-working-while-using-struts2-rest-api-implementation – Kavin Raju S Feb 10 '22 at 10:14