Both these sentences are grammatically correct and, aside from (1) being a bit more informal, mean the same thing. As far as I know you can always replace "the way" (when used like this) with "how."
However, "the way" has a narrower meaning, so there are several contexts in which you can use "how" but not "the way." You cannot use "the way" in situations where "how" means "to what extent" rather than "in what way": I love how beautiful you are is fine, but I love the way beautiful you are is nonsense.
Naturally "the way" cannot be used in questions. How do you get there? cannot be The way you get there?
It's also less appropriate in embedded questions: I wonder how they do that is fine but I wonder the way they do that is not. However, this is only the case when what is embedded is an indirect question (usually indicated by what verb is used with it) - I know how they do that and I know the way they do that are both fine.