Student jailed after being found with gun at school