Quite often in movies you see a group of soldiers run on an open field directly into the enemy who has a wall of spears and shields ready, I'm guessing this scenario must have happened at least a few times throughout history and I've been thinking, is there any type of strategy to survive such a charge? It feels like there is very little you can do, I mean, did the men in the front line basically just sacrifice themselves? If you're running towards a bunch of spears, isn't it virtually impossible to not get impaled?
I'm talking about an attack like this, obviously almost every main character in LOTR has a plot shield, but in a real battle, is it realistic for someone to survive that or would you basically be fucked 9 times out of 10 no matter how skilled you are?
Soldiers didn't just ram themselves onto spears. When faced with a line of heavy infantry who were standing in close order and fully prepared to receive a charge, they knew that slamming full-force into that line would probably be ineffective. A scene from the siege of Majorca in 1229 illustrates the difficulties of getting troops to assault such a position:
And so great was the multitude of Saracens, that they stopped them [the Christian forces of James I of Aragon] with their lances; and the horse reared up, unable to pass because of the density of the lances...And the knights and the foot soldiers carrying shields were so near the Saracens that they could attack them with their swords, so close in fact that nobody dared to put out his arm, for fear that some sword of the other side would wound him on the hand.
English cavalry at Bannockburn, contrary to some depictions, did not rush headlong into the Scottish infantry, aside from a few overly brave fools who were killed near-instantly. For the most part, cavalry attacking a defensive infantry formation would pull up just before impact and throw spears, swords, and other implements into the formation in an attempt to get them to break. The defending infantry might run out and attempt to stab the horses of the attacking cavalry. Clifford Rogers notes that the descriptions of such actions at both Hastings in 1066 and Bannockburn in 1314 have remarkable similarities in terms of the tactics used. Contrary to some theories about a supposed "infantry revolution" of the late medieval period, medieval warriors were well aware of the capacity of men on foot to hold a line and defend themselves against attacking footsoldiers or cavalry.
This question has been answered before in regards to Romans vs. Macedonian style Phalanxes.
As /u/Jangziya points out with the example of the battle of Cynoscephalae, attacking a massed spear formation head on is suicide without proper preparation and tactics. The Romans solved this problem a couple of different ways:
They equipped their infantry with javelins to disrupt enemy formations before a charge.
They exploited the lack of maneuverability inherent in phalanxes using the Maniple System to force the enemy onto rough terrain, on which phalanxes perform poorly. This system also enabled infantry to flank the enemy formation and engage them from the sides and rear, the direction the spears or pikes were not pointed.
They also used auxiliary cavalry to flank the enemy.
They used auxiliary missile units to "soften" the enemy formation before engaging with infantry.
When infantry did charge, they did so in a wedge formation, breaking through a single point in the phalanx, allowing them to once again, attack from the sides.
Romans used a shield and sword, which meant their formation had to be looser to leave room to engage. Once the enemy formation had been disrupted, this gave them a significant advantage against spear armed opponents.