<jsp:useBean id= "instanceName" scope= "page | request | session | application" class= "packageName.className" type= "packageName.className" beanName="packageName.className | <%= expression >" > </jsp:useBean>
In this example, we are simply invoking the method of the Bean class.
EmployeeData.java
package com.dineshonjava; /** * @author Dinesh Rajput * */ public class EmployeeData { public String getAge(String name){ return "Age of "+name+" is 27 Years"; } public int getSalary(){ return 70000; } public int getArea(int height, int width){ return (height*width); } }
index.jsp
<jsp:useBean id="obj" class="com.dineshonjava.EmployeeData"/> <% String age = obj.getAge("Dinesh Rajput"); out.println(age); %> <br/> <% int salary = obj.getSalary(); out.println("Salary is Rs. "+salary); %> <br/> <% int area = obj.getArea(200, 100); out.println("Area of Home is "+area+" Sq-ft" ); %>
Make a dirctory myapp/com/dineshonjava/ at webapp folder of tomcat server at
C:Program Files (x86)Apache Software FoundationTomcat 7.0webapps
and make class file EmployeeData.class and create index.jsp file with in myapp folder.
Now restart tomcat server and hit the following url.
http://localhost:8080/myapp/index.jsp
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…