This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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.