J.R.R. Tolkien was studying at Oxford in England when WW1 started. He fought in WW1 and lived through WW2. The Lord of the Rings trilogy was written at the end of WW2, but Tolkien himself said that those critics looking for signs of and parallels to WW2 in his writing were missing the fact that WW1 actually had the biggest impact on him. His experience with battle and the death of most of his friends during WW1 is what had the profoundest effect on his life and therefore his writing. His idea of a "hero" for example, shifted away from the traditional hero and focused more on a world that was capable of destroying itself.
While at Oxford, Tolkien studied languages. It was here that he began to develop his own language (one originally conceived in childhood) that was later put in TLR as "elvish." During the war, this talent also served him personally. He and his wife devised a secret code between each other so that in his letters home, Tolkien could send word of his location and his wife could track where he was at all times. In this way, she had a more direct connection to his location and therefore his safety.
During WW2, the atomic bomb was a major event which solidified Tolkien's distrust of technological advancement and corruption of power.
Finally, Tolkien was a deeply religious man. Raised as a Catholic, his faith is evident in all of his works, which have largely been looked at as allegories to the Christian journey. Whether or not this was Tolkien's original intention, it cannot be denied that there are certainly parallels in his themes of good vs. evil as well as redemption and salvation that mimic very strongly the spiritual journeys of followers of Jesus Christ.