You can call java code from JSP pages in the following ways.
Place all Java code in JSP page. Appropriate only for very small amounts of code.
- Call Java code indirectly
Develop separate utility classes. Insert into JSP page only the Java code needed to invoke the utility classes.
Develop separate utility classes structured as beans. Use jsp:useBean, jsp:getProperty, and jsp:setProperty to invoke the code.
Have a servlet respond to original request, look up data, and store results in beans.
Forward to a JSP page to present results. You could also use frameworks like Struts.
Use shorthand syntax to access and output object properties. Usually used in conjunction with beans and MVC.
Develop tag handler classes. Invoke the tag handlers with XML-like custom tags.
Now to learn all this there are lots of materials out there. Don't try to learn it like a subject but rather search and try solutions for your real or practice problems.
Stackoverflow itself has some interesting posts on these subjects.
How to avoid Java code in JSP files?
Hidden features of JSP/Servlet