Greetings,
I have a servlet which pulls an “action” parameter from a querystring. Based on this string I perform the required action.
What is the best way to check the value of the “action” parameter. Currently my code is a long if, else if, else if, else if…when I’d rather have some kind of mapping from string to method where I didn’t have so many branch conditions.
Regards,
Ken
Populate a
Map<String, Action>whereStringrepresents the condition for which you would like to grab the action andActionis the interface which you’ve definied for your actions.E.g.
You can find a detailed example in this answer.