I have a java class which performs some operations on files. Since the java code is huge I don't want to write this code in jsp. I want to call the methods in jsp whenever required.
Please tell me the path where I need to keep this file. Also some example code how to use it would be helpful.
JSP 2.0 has no syntax for calling a public nonstatic JavaBean method from a scriptless JSP page. This article solves that issue by providing a JSP 2.0 simple tag with dynamic attributes. Note: You can download this article's source code from Resources.
Simply create an object of the class using <jsp:useBean> and call the method using JavaServer Pages Standard Tag Library or Expression Language that is more easy to use and less error prone. Read more about Implicit Objects that might help you.
In the servlet (which runs before the JSP):
Person p = new Person(); // instantiate business object
p.init(...); // init it or something
request.setAttribute("person", p); // make it available to the template as 'person'
In the template you can use this:
your age is: ${person.age} <%-- calls person.getAge() --%>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With