0

I want to be able to run a Struts 2 action when there is no mapped action found.

The reason I need to do this is because my users can have URLs like www.example.com/someValue.

someValue is a variable and I don't know what the value could be. I want to be able to run a specific action if the page is not found.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Zaheer Baloch
  • 536
  • 3
  • 9
  • 28
  • If it should have a value then it might map to some variable and return error result if the value is wrong. Otherwise you just get an invalid mapping because the value is treated as action name and if not such name exists then default action will call if configured. – Roman C Sep 17 '14 at 18:26
  • Thanks @RomanC. I did tried exactly that by having an action with name="/${keyword}", but it never works and I keep getting an error that there is nothing defined for /abcd. I think struts filter outs the request even before it gets to evaluate /${keyword} – Zaheer Baloch Sep 17 '14 at 18:43
  • Try without dollar sign because I think it's not valid syntax for regexes. You should also post the configuration file. – Roman C Sep 17 '14 at 19:18
  • Look at wildcard actions and regex capture matching – Dave Newton Sep 17 '14 at 21:59
  • 2
    See http://stackoverflow.com/q/16293143/1700321. – Aleksandr M Sep 18 '14 at 08:21
  • 1
    `my users can have URLs like www.example.com/someValue` also take a look at this: http://stackoverflow.com/a/23788400/1654265 – Andrea Ligios Sep 18 '14 at 08:32
  • Thank you so much @AleksandrM & Andrea. Andrea's suggestion that I was actually looking for and it worked for me. Thank you so much guys! – Zaheer Baloch Sep 18 '14 at 11:47

0 Answers0