Professional Documents
Culture Documents
: 05
o Title:
Implement the sample program demonstrating the use of Servlet.
e.g., Create a database table ebookshop (book_id, book_title, book_author, book_price,
quantity) using database like Oracle/MySQL etc. and display (use SQL select query) the
table content using servlet.
o Date of performance:
o Date of submission:
o Sign:
Assignment No.05
o Aim:
Implement the sample program demonstrating the use of Servlet.
e.g., Create a database table ebookshop (book_id, book_title, book_author,
book_price, quantity) using database like Oracle/MySQL etc. and display
(use SQL select query) the table content using servlet.
o Hardware/Software Requirements:
Software:
1. Any Operating System
2. JDK 7 or later
3. Editors : Eclipse
4. Web browser
5. Tomcat 7 or later
o Theory:
❖ Servlet :
1. init() method:
The Servlet.init() method is called by the Servlet container to indicate
that this Servlet instance is instantiated successfully and is about to put
into service.
Syntax:
public class MyServlet implements Servlet{
public void init(ServletConfig config) throws ServletException {
//initialization code
}
//rest of code
}
2. service() method:
The service() method of the Servlet is invoked to inform the Servlet
about the client requests.
This method uses ServletRequest object to collect the data requested
by the client. This method uses ServletResponse object to generate
the output content.
Syntax:
3. destroy() method:
The destroy() method runs only once during the lifetime of a
Servlet and signals the end of the Servlet instance.
Syntax:
public void destroy()
Example,
Class.forName("oracle.jdbc.driver.OracleDriver");
Example,
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","password");
Example,
Statement stmt=con.createStatement();
Example,
Example,
con.close();
o Conclusion:
Thus, we have implemented the sample program demonstrating the use of
Servlet.