Calling a java method in jsp

前端 未结 5 445
刺人心
刺人心 2020-11-28 10:50

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

5条回答
  •  抹茶落季
    2020-11-28 11:19

    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() --%>
    

提交回复
热议问题