WTL Assignment No. 6
WTL Assignment No. 6
: 06
o Title:
Implement the program demonstrating the use of JSP. e.g., Create a database table
students_info (stud_id, stud_name, class, division, city) using database like
Oracle/MySQL etc. and display (use SQL select query) the table content using JSP.
o Date of performance:
o Date of submission:
o Sign:
Assignment No.06
• Aim:
Implement the program demonstrating the use of JSP. e.g., Create a database
table students_info (stud_id, stud_name, class, division, city) using database
like Oracle/MySQL etc. and display (use SQL select query) the table content
using JSP.
• Hardware/Software Requirements:
Software:
1. Any Operating System
2. JDK 7 or later
3. Editors : Eclipse
4. Web browser
• Theory:
❖ JSP :
A JSP page consists of HTML tags and JSP tags. The JSP pages are
easier to maintain than Servlet because we can separate designing and
development. It provides some additional features such as Expression
Language, Custom Tags, etc.
• Advantages :
1. Extension to servlet
2. Easy to maintain
3. Fast Development
4. No need to recompile and redeploy
5. Less code that Servlet
Note: jspInit(), _jspService() and jspDestroy() are the life cycle methods of JSP.
As depicted in the above diagram, JSP page is translated into Servlet by the help of
JSP translator. The JSP translator is a part of the web server which is responsible
for translating the JSP page into Servlet. After that, Servlet page is compiled by the
compiler and gets converted into the class file. Moreover, all the processes that
happen in Servlet are performed on JSP later like initialization, committing
response to the browser and destroy.
index.jsp
Let's see the simple example of JSP where we are using the scriptlet tag to put Java
code in the JSP page. We will learn scriptlet tag later.
<html>
<body>
JSP Scripting element are written inside <% %> tags. These code inside <% %> tags
are processed by the JSP engine during translation of the JSP page. Any other text in
the JSP page is considered as HTML code or plain text.
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,
while(rs.next()){
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
Example,
con.close();
• Conclusion:
Thus, we have implemented the program demonstrating the use of JSP.