System.out.println ("test");
That is java and you cannot execute that on client side.
You might looking for
console.log("");
And while page loading it's printing because the jsp you are submitting processing on server side and java code executes there.
In short: