Discouragement comes from one thing, and one thing only: thinking discouraging thoughts. Changing the content of one's thoughts changes the entire picture!
Discouragement often comes from one's limited self-image.
When you view yourself in a positive light and see what you've done as valuable and important, even though things didn't work out the way you were hoping, you still feel positive about the effort you put into doing something worthwhile. You know that effort is up to you; results are up to the Almighty. You realize that your own value and worth are constant, and then think about your new wisest course of action for now.
If you ever feel discouraged, you can say to yourself, "Right now I am feeling discouraged because of the thoughts that I am thinking. What are some wiser thoughts that I can think right now?"
(From Rabbi Zelig Pliskin's book: "Building Your Self-image and the Self-image of Others" (Artscroll) Chapter 86)