Servlets Assignments

#1. Develop below html and Java Servlet files, which performs the below specified functionality

When successfully logged in, forward to Welcome Servlet. When failed to login, include login.html.
WelcomeServlet need to start a new session, and store username in Session attribute.
Display username(from session) in all Servlets.
Provide hyper links to display a Servlet from any other Servlet.
Destroy session, when logout link is clicked. logout link need to be displayed in all Servlets.

If you try to open any servlet directly from url, without logging in, it need to display a message, “login to continue”.

#2. In the above problem, try to add session time out functionality, i..e when user does not send a request for 3 mins, session need to be timed out, and automatically destroyed.

#3. In Servlets RequestDispatcher, from processing servlet try to include two other resources separately, ensure that response received by Browser has output from Processing Servlet, and other two included resources as well.

#4. Try to retrieve Servlet Context initialization parameter values( from the deployment descriptor, web.xml) and print them. In the same web app, try creating another servlet, which can access same Servlet Context initialization parameters.

#5.In Servlet RequestDispatcher, from Processing Servlet, forward the request to some other Servlet, and this some other servlet need to include another resource(an HTML or Servlet)

#6.Use HttpSession to find number of seconds spent by user on each page. Update the details in database table.

#7.Use Cookie and display html page to user, and let user select his/her own back ground color, from drop down options provided in the html page. When user visits the page again later, the background of html page need to be the color which has been selected by user, in earlier session. Validity period of cookie can be one week.

#8. Write a Filter for a Servlet or JSP, which removes Parameters with certain name in the request.

#9. Write a Servlet1, which forwards request to other Servlet2. Servlet1 need to adds few parameters which can be retrieved and displayed by Servlet2.

#10. Write a Servlet, which has login and signup functionality. MySQL database can be used, to store login details. User Account need to get locked for 1 day after three unsuccessful login attempts due to wrong password.

#11. Write a Servlet, and using HttpSessionListener try to get total number of currently logged in to the site.

#12. Use JSP/Servlet to develop Shopping Cart.

#13.Use JSP/Servlet to develop simple Payment Gateway.

#14. Generate PDF Bill using JSP

#15.Use AJAX to validate each field in Signup Form, and display error if an entered value is invalid, and display error beside respective field if its value is invalid.

You may also like to read:

Basic Java Assignments

Below are few Java assignments you can try to develop programs, and get more confidence in Java.
1a. Declare one dimensional array of primitive integers, of size 20.
Write a program to reverse the elements of array, and print reversed array.

1b. From a given integer, extract each digit, and display each digit. NOTE: integer can have any number of digits(ofcourse within integer range)

1c. Display all numbers between 1 and 40, except number, which is multiple of both 2 and 3.

2.Declare two dimensional arrays of primitive floats, with 6 rows and 8 columns.
Write a program to exchange row and column numbers, and print the final elements in rows and columns.

3.Write a class, with a method public void show(), and print Hello World message from this method.
In main method create object of above class, and invoke show() method.

4.In addition to above Assignment 3, add a default constructor[print message in constructor body] to the class.
In main method create object of above class, and invoke show() method. In output observe the order in which the messages are printed.

5.Write a class(say class A) with few data members, and methods.In another class write below methods which
a.takes object of class A as parameter,
b.create object of class A and return the object.

6.Method overload: write a class with 4 methods named add() with different number and type of parameters.add() methods need to return added value of parameters.
From main method invoke the 4 add() methods, get the return values, print them.

7.Write a class with four static methods(add, , each accepting 2 parameters )computes mathematical operation and prints the result.Invoke these static methods from main method.

8.Write a program with all usages of this keyword.
For eg. this(), this. , this

9.Invoke static method, and use static data members from another static method.
Also invoke non static method, and use non static data members from a static method.
observe the difference…

10.Serialization:Write an Employee class with id,name, father name, photo url as data members. use transient keyword for photo url. Serialize the object of Employee class and de serialize it. print data members of de serialized object.

11.Open file using FileInputStream, read one line at a time from file, and print lines on console.
Hint:use BufferedReader

12.Use SequenceInputStream, to combine input from four different files, and write all the content to fifth file.

13.Create a class with 2 data members of any type, along with get and set methods. Then declare an array of this class type, and store objects in the array. Now iterate(using for loop) through each object in array, print object details with get method. main method throw an exception, using throw keyword, catch the exception using catch block. In catch block, further throw the exception.Hint: use throws keyword also

15.Which is base class of all classes in Java?

16.Write a class which inherits from String class, observe it.Also try to inherit from StringBuffer, Integer, Float, classes also.

17.Write a program for Nested try blocks, and observe the execution flow.

18.In Collection, what is difference between Object based Collection and Generic version Collection? What are the scenarios in which each of them are preferred.

19.What is output of below program

public class Test{
    void sum(int i,int j)
        int k=0;

    public static void main(String args[])
        Test obj = new Test();
Ans: Exception in thread "main" java.lang.StackOverflowError occurs
20.Using printStackTrace(), get the stack trace into a String, instead of printing to console
21.There is a file with some data as shown below

f1,f2 means f1 is friend of f2, and so on. Write a program to read contents of this file and remove duplicate entries, and write non duplicated entries to another file.

22. Is it possible to change the current object to which this is reference? In other words, is below statement  valid in Java
this = new Xyz();//Xyz is some class

23. A two dimensional Array with 4 rows and 5 columns, and type float. Add elements of each row, display total and average of each row.

Servlets interview Questions

  1. Using Servlets develop page view counter, count value can be maintained in database. Use cookies to find unique visits to the web page
  2. JSP write Filter, with a specific url pattern. And check that Filter need to get invoked only when request url matches the pattern
  3. Write a Filter, for JSP, which checks the ip address from where request has originated, return without processing request if the request ip address is in a specific range
  4. On webpage provide option to select background color of the page, store this back ground color in cookie. Later, when user displays the cookie value(background color), to display the webpage with selected back ground color
  5. Create custom JSP tag, use this custom tag in your JSP code

You may also like to read:
Core Java Assignments 1