If you want to be able to evaluate arbitrary function code, that sounds like a "scripting" language to me. There is a lot of activity in the area of scripting languages for Java - Jython, Beanshell, JRuby, Groovy are some that come to mind. A more detailed explanation of what you want to do would help.
Naturally you should never put any code of any significant complexity directly in a JSP. Create a helper class that can be tested outside the servlet environment.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com