what is setting? and how important is to understand the setting in order to understand a poem ? explain with examples
The setting is simply the time and place of the action of a piece of literature (in your case, where and when the poem takes place). In a poem, it might be a little harder to determine the setting, but it could be a vague idea that you get from the poem.
For example, in this love sonnet(83) by Pablo Neruda, you can determine the setting by reading the first few lines of the poem. Neruda is lying next to his girlfriend while she is sleeping. It is nighttime.
See if you get that, too:
It's good to feel you close in the night, Love,
invisible in your sleep, earnestly nocturnal,
while I untangle my confusions
like bewildered nets.
In this poem, when you understand the setting, you can have a better insight to what drove Neruda to write this poem. If you were to do a little more background research, you would also find that he was a political activist with a penchant for torrid love affairs. This information (the background and the setting) give you a deeper insight into the meaning of the poem. It helps you to understand it better.
In a more direct poem, you can pick out the setting very easily. In Robert Frost's Stopping by Woods on a Snowy Evening, the setting is literally by the woods, which you can gain from the title.
Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.