Abu Qatada (Radi'Allahu anhu) reported
Allah's Messenger (Sall'Allahu alaihi wa sallam) as saying:

A good vision is from Allah
and a bad dream (hulm) is from the satan;
so if one of you sees anything
(in a dream) which he dislikes,
he should spit on his left side thrice
and seek refuge with Allah from its evil,
and then it will never harm him.

Abu Salama (Radi'Allahu anhu) said:

I used to see dreams weighing
more heavily upon me than a mountain;
but since I heard this hadith
I don't care for it (its burden).

(Sahih Muslim ~ Book #029, Hadith #5616)

__________________________________________________ _____________

What to Do after having a nightmare?

On having a good dream:

On having a good dream recite "Alhamdulillah"
and relate it to an intimate companion of understanding
(So that the companion does not interpret the dream badly).

On having a bad dream:

If a person has a bad dream,
then spit three times on his left side
and turn to the other side
or stand up to perform two rakah salah
reciting the following dua three times:

أَعُوذُ بِاللَّهِ مِنَ الشَّيْطَانِ الرَّجِيمِ وَمِنْ شَرِّ هَذِهِ الرُّؤْيَا

"I seek refuge in Allah from the accursed Satan
and from the evil of this dream."

The dream will not cause any harm.
(Misjkat, Hisnul Hasin)

It is a great sin to conjure a false dream and narrate it.