Java

Servlet and JSP Practice Questions

The following list provides some of the Servlet and JSP Practice Questions and their solutions.

  1. Write a program that displays “Servlet Tutorial – programmingempire.com”.
  2. Create a servlet that displays the request headers and their values.
  3. Further, create an HTML form that contains text fields, text area, radio buttons, drop-down list, checkboxes, and date. Also, create two different servlets to display the values entered by the user using the GET and POST methods.
  4. Create a servlet that displays the servlet config and servlet context parameters. For this purpose, you can create more than one servlet.
  5. In order to greet the first-time visitors, create a servlet that displays the message “Welcome to the programmingempire.com. You are visiting the first time!”. Subsequently, it should display “Welcome back to the programmingempire.com!”;
  6. Create a servlet that displays all the cookies in a tabular form, if they exist. Otherwise, display the message “No Cookie on Programmingempire.com”.
  7. Similarly, create another servlet that displays the number of visits by a user using the session tracking. Also, display the session id and other details of the session object.
  8. Write a program in JSP that prints the current date and time using JSP expressions.
  9. The following exercise makes use of both JSP and the servlet. At first, create an HTML form that contains a text field and a submit button. When the user enters a number in the textbox and clicks on the submit button, it invokes a servlet. The servlet finds all prime numbers less that the given number. Further, it inserts all of these prime numbers in an ArrayList. After that, the servlet forwards the control to a JSP page that prints the contents of the JSP page in a tabular form.
  10. Write a program in JSP that prints n numbers and their factorials in a tabular form. Also, get the value of n from the user using the GET method.

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 *