Having received word from the Lord that He was going to use Babylon, an evil nation, to judge Israel, Habakkuk was naturally very upset. This isn't what he wanted at all. Here he was, praying for an end to evil, but God tells him a greater evil is going to befall his beloved country. And yet, Habakkuk knew the Lord knows best. God knows exactly what He's doing, and when all is said and done, all will be put right. His response: I will rejoice in the Lord, I will joy in the God of my salvation.
Part of human nature is to set aside joy when things don't go our way. When God doesn't answer our prayers in exactly the manner we pray, it can be very unnerving. Sometimes, it can even be devastating. Habakkuk was so grief stricken that he says rottenness entered his bones (Habakkuk 3:16). But the difference between joy and happiness is that joy remains regardless of our circumstances. Even if evil will arise to swallow up our entire nation, joy tells us for sure that God is on the throne, and He will put things right.