I was wondering about the possibility to send Java Code to a servlet that the servlet will take and execute it?
For example I would send a chunk of code as String, which will be added and executed. Can anybody think of a way of how I would approach this?
This is certainly possible – you could send the compiled bytecode Base64-encoded, then decode it at the servlet and use a classloader to load it.
Or you could send a jarfile similarly encoded, save it to disk and add it to a custom URLClassLoader.
You may have major security issues if the code is untrusted, though.
See What are the security risks I should guard against when running user-supplied Java code?