Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
145 views

11 Three-Tier Application Using Servlet-Student Marklist DATE:21.9.10

This document describes the development of a three-tier web application for maintaining a student marklist database using Java servlets. It includes: 1) Creating an HTML form to accept student data and submit to a servlet. 2) The servlet code uses JDBC to connect to an Access database, inserts the submitted student data, and retrieves the student records to display in an HTML table. 3) The output displayed is the student marklist retrieved from the database.

Uploaded by

omprakkash1509
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views

11 Three-Tier Application Using Servlet-Student Marklist DATE:21.9.10

This document describes the development of a three-tier web application for maintaining a student marklist database using Java servlets. It includes: 1) Creating an HTML form to accept student data and submit to a servlet. 2) The servlet code uses JDBC to connect to an Access database, inserts the submitted student data, and retrieves the student records to display in an HTML table. 3) The output displayed is the student marklist retrieved from the database.

Uploaded by

omprakkash1509
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

CS1404-INTERNET PROGRAMMING LAB

REG.NO:11407104026

11 THREE-TIER APPLICATION USING SERVLET-STUDENT MARKLIST DATE:21.9.10 Aim: Create a Three-tier application for maintaining Student Mark list Hardware requirements: Intel pentium Processor IV 128mb RAM Software requirements: Jdk1.6.0 Algorithm: 1. Create a data base for storing student information 2. Open the database using the JDBC ODBC Drivers using the methods of class 3. Using Connection, Statement , RecordSet classes select the record from the tables using suitable Query 4. Using the PrintWriter class create a decorative form to display the marklist 5. Fetch the records one by one from the record set and display them close the database connection

CS1404-INTERNET PROGRAMMING LAB

REG.NO:11407104026

THREE TIER APPLICATION-STUDENTS DATABASE HTML CODING: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <script> function validate() { document.form1.submit(); } </script> <body> <form name="form1" method="post" action ="http://localhost:7001\student1\insert""> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="15%">Name</td> <td width="85%"><input name="name" type="text" id="name"></td> </tr> <tr> <td>Roll No </td> <td><input name="rollno" type="text" id="rollno"></td> </tr> <tr> <td>Mark1</td> <td><input name="mark1" type="text"></td> </tr> <tr> <td>Mark2</td> <td><input type="text" name="mark2"></td> </tr> <tr> <td>Mark3</td> <td><input type="text" name="mark3"></td> </tr> <tr> <td>Mark4</td> <td><input type="text" name="mark4"></td> </tr> <tr> <td>Mark5</td> 2

CS1404-INTERNET PROGRAMMING LAB

REG.NO:11407104026

<td><input type="text" name="mark5"></td> </tr> <tr> <td><input type="submit" name="Submit" value="insert"></td> <td><input type="button" name="Button" value="View All" onClick="window.location.href='view.htm'"></td> </tr> </table> </form> </body></html> SERVLET CODING: import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; public class insert extends HttpServlet { Connection conn=null; Statement stmt=null; ResultSet rs=null; public void init(ServletConfig config)throws ServletException { super.init(config); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn = DriverManager.getConnection("jdbc:odbc:stud"); stmt = conn.createStatement(); } catch(Exception e) { System.out.println("Driver not connected Error :"+e); } } public void doPost(HttpServletRequest request, HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter pw = res.getWriter(); String name = request.getParameter("name"); int rollno = Integer.parseInt(request.getParameter("rollno")); 3

CS1404-INTERNET PROGRAMMING LAB

REG.NO:11407104026

int mark1 = Integer.parseInt(request.getParameter("mark1")); int mark2 = Integer.parseInt(request.getParameter("mark2")); int mark3 = Integer.parseInt(request.getParameter("mark3")); int mark4 = Integer.parseInt(request.getParameter("mark4")); int mark5 = Integer.parseInt(request.getParameter("mark5")); int total = mark1+mark2+mark3+mark4+mark5; double avg = total/5; try { stmt.executeUpdate("INSERT INTO student VALUES('"+ name+"','"+rollno+"','"+mark1+"','"+mark2+"','"+mark3+"','"+mark4+"','" +mark5+"','"+total+"','"+avg+"')"); rs=stmt.executeQuery("select * from student"); pw.println("<HTML>"); pw.println("<HEAD><TITLE>STUDENT DATABASE</TITLE></HEAD>"); pw.println("<H2>STUDENT MRKLIST<H2>"); pw.println("<TABLE BORDER=1 cellspacing=0 cellpadding=0>"); pw.println("<TR> <TH>NAME</TH> </TH> <TH>ROLLNO</TH> <TH>MARK1</TH> <TH>MARK2</TH> <TH>MARK3</TH> <TH>MARK4</TH> <TH>MARK5</TH> <TH>TOTAL</TH> <TH>AVERAGE</TH> </TR> "); while(rs.next()) { pw.println("<TR>"); pw.println("<TD>" + rs.getString("name") + </TD>"); pw.println("<TD>" + rs.getString("rollno") +</TD>"); pw.println("<TD>" +rs.getString("mark1") +</TD>"); pw.println("<TD>" + rs.getString("mark2") + /TD>"); pw.println("<TD>" + rs.getString("mark3")+ /TD>"); pw.println("<TD>"+rs.getString("mark4")+"</TD>"); pw.println("<TD>"+rs.getString("mark5") +</TD>"); pw.println("<TD>" + rs.getString("total") + "</TD>"); pw.println("<TD>" + rs.getString("avg") + "</TD>"); pw.println("</TR>"); } pw.println("</TABLE>"); pw.println("</BODY>"); pw.println("</HTML>"); } catch(Exception e) { System.out.println("SQLException :"+e); } } }

CS1404-INTERNET PROGRAMMING LAB

REG.NO:11407104026

DATABASE:

OUTPUT:

RESULT: Thus the Java servlet program has been executed, displaying the Student marklist

You might also like