The Napoleonic wars were quite long, I expect initially people would have fought to avoid a foreign invasion, but people regularly enlisted to fight for the ancien regimes.
I am trying to understand why non-aristocrats would have opposed Napoleon's wars particularly toward the middle and the end after he had founded/refounded countries and limited feudalism. This might overlap a bit with what motivated French people to oppose the revolution, I just find it odd that commoners, urbandwellers, and peasants would have been loyal to the feudalistic systems Napoleon overthrew.
Good question! But to answer it, you first have to look at the term of nationalism, and my main focus would be Germany, as there is there my knowledge is best.
Nationalism is often divided into civil nationalism (you follow our laws and are born within our borders) and ethnic nationalism (you look and speak like us). The first one was to a great degree a result of the politics of the French Revolution and the enlightenment (universalism), which was furtherly developed by Napoleon as a political tool. The second version can be seen as a germanic reaction to the french conquests. Germany consisted at the time of several smaller and medium states, that all had a tradition of maintaining their sovereignty. These feelings of sovereignity slowly dissipated through the napoleonic invasion (classic us vs them) and were shored up by writings from german idealism and romanticism (see: Fichte, Herder, Schlegel).
These thinkers promoted the bond between german people and their soil, which was thus able to rally germans against the «foreign invaders». (Of course, strong aristocrats who wanted to defend their lands because of economical arguments and therefore conscripted peasants were an important part too).
One could also argue that these tendencies were roots of the national socialistic Blut und Boden (Blood and soil) through philosopical perversion the coming 150 years
When it comes to Italy, i know much less, but looking at the political and ethnic sentiments of Piedmont-Savoy and it’s predecessors would be a good place to start.
For further reading, I reccomend Eric Hobsbawms «Nations and Nationalism since 1780)