When you talk about "the military," you're talking about thousands and thousands of people! So you can't make a blanket statement. Some folks have opinions based on their own experience: they did/didn't know good/not-so-good military people, etc. Some go by what they hear from the sources that are most important to them. Keep in mind that the media organizations also have mindsets.
In actual fact, there are people worth respecting and some who are not, as individuals.
When we moved here, we moved to a "military town" (well, it was a town back then). Some people said, "Oh, you'll love it - military folks are the best!" Others said, "Keep your doors locked and watch what parts of town you walk in." What did we find? Both. Some people are worth respecting and some are not.
There is also a difference between an opinion of the military as individuals and an opinion of the military as an organization.
So don't worry too much about the put-downs. Perhaps the best you can do is encourage the soldiers you know to be the best they can be, both in character and in education. (Mark Twain wrote, "Some people get a good education without going to college; the rest get their education after they get out.")
My younger son is an Army Major, so of course I have a good opinion! But I know there are some enlisted/officer people I might not think highly of; and, if I were to forget that, my son would remind me!
People have the same sort of generalized opinions of the teaching profession, the ministerial profession, the medical profession, the selling profession, the ditch-digging profession (with those big machines), and the taxi-driving profession. One would do well to remember that they are based more on impressions than knowledge.