If you look at the modern Middle East from 1917-2017, it's been a history of European and American meddling and aggression in almost every country there. We are currently occupying and bombing the countries on either side of Iran (and then we wonder why they might want a nuclear defense.) We are bombing Syria, Yemen, Pakistan, we bombed Libya, we have supported murderous tyrants and overthrown democratically elected leaders. We arm the Zionist regime to the teeth and turn a blind eye to the abject destruction of the Palestinian people. We pay lip service to human rights, but what we've always wanted is oil and safe access to it. We've also got Somalia in a choke hold and don't seem to have any interest in helping them.
If I was a young Muslim, even with a university education, it would be hard not to think the West is engaging in a pretty ferocious and comprehensive military campaign against Islam itself. We've poked this hornets nest for 100 years, and the result is them fighting back, as cowardly as it is to drive a truck into innocent pedestrians. I despise these criminals, and I do agree that Europe has been too lenient with it's immigration laws. Sweden has had very little to do with any policies pertaining to geopolitics of The Middle East, so attacks like this in a country like that, as well as their rioting and crime problems really lay bare the folly of liberal immigration practices given the times we live in.
Is there an answer? I'd start with getting off oil and getting out of their countries.