The celebrity performed pirate songs and dances for the pupils during the visit with four other cast members on Wednesday.
Depp is currently filming "Pirates of the Caribbean: On Stranger Tides" at the nearby Old Naval College.
Teachers at the school say that they encourage pupils to write for a real audience in classes.
"This just goes to show it can reap great rewards," said acting head teacher Jo Graham.
"Pirates of the Caribbean: On Stranger Tides" will be in theaters summer of 2011.
The Associated Press contributed to this report.