You cant write Java functions (methods) within the the <% %>. The code in in JSP will be generated inside the _jspService method. So that is the reason you get the compilation errors.
To put java function inside generated JSP class file you need to put in the <%! %> . This will make the code to be generated inside the JSP class file. Beware JSP instances are singleton, so if you declare any variable inside the <%! %> (class scope), it will be shared across all the requests from all the users.
You can use the session object to store the values pertaining to a particular user.