Java

Using JavaBeans in a JSP

This article explains Using JavaBeans in a JSP. Further, a few examples of using JavaBeans in a Java Server Page (JSP) are also provided.

Basically, a JavaBean is nothing but a Java class that follows certain conventions. It represents a reusable software component. A JavaBean must define a public default constructor. Also, all of its properties must be private. These private properties are accessible using public getter and setter methods. Since JSP technology supports JavaBeans, so the methods of a JavaBean can be called from a JSP web page.

The following practice questions on Using JavaBeans in a JSP help you understand this concept.

  1. Write a program that displays an HTML form to accept customer orders. Also, create a JavaBean for the Orders. Bean properties should be set using Request parameters. Calculate and display the order value using price and quantity ordered.
  2. Create an HTML form that takes a number from the user. Also, create a servlet that forwards the control to a JSP page according to the user input. When user enters 1 it should display AboutUs.jsp. When user enters 2, ContactUs.jsp should display. Otherwise, error.jsp should display.
  3. The following application makes use of an HTML form, JSP, servlets, and JavaBean. At first create an HTML form that displays fields book_id, title, price, and a submit button. A JavaBean should contain the corresponding properties. When user clicks on the submit button, a JSP page should retrieve the values entered by the user and invokes a servlet that save these values in a database table. For this purpose, create another utility java class. Also, perform select, delete, and update operations on the database using Java servlets.

Further Reading

Java Practice Exercise

programmingempire

Princites

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *