jsp:use bean tag is used to declare and used object using tag format in jsp page.
Bean object is declared using use:bean tag in jsp page. set:property tag is used to set the values and get:property tag used to get the values from bean object.
Scope for jsp:bean is set to request so that when a request is transfer to another page its also accessible there.
following is the list of important attributes of jsp:usebean tag β‘ id (name of the object) β‘ name (name of the fully qualified class name of bean) β‘ scope (application,request,session and page), default is page.
In this example bean values are set in process.jsp and then its transferred to welcome.jsp using request dispatcher. Welcome.jsp access the values get the values which were set in process.jsp page.
Summary of files used in this example β‘οΈ index.jsp (to accept client input) β‘οΈ process.jsp (to declare and set the values in bean) β‘οΈ UserBean.java (user bean POJO file) β‘οΈ welcome.jsp (welcome page to display)
βοΈ jsp:useBean standard action tag is use to establish a connection between a jsp page and a java bean. βοΈ In web applications of java, jsp and java bean communication is required in the following two cases: 1οΈβ£In a real-time MVC project, a model class (business class) will set the data to a java bean and a jsp (view) will read the data from a bean and finally displays it on the browser. 2οΈβ£If multiple jsp pages need common java logic then it separates that java code into a bean and then we call the bean from jsp.
Video features the following: π How to define Bean class in java π How to use bean class in JSP scriplet π How to use bean using jsp:useBean
It contains the following files π Index.jsp π process.jsp π UserBean.java