Sunday 23 June 2013

16. Assume that the information regarding the marks for all the subjects of a student in the last exam are available in a database, Develop a Servlet which takes the enrollment number of a student as a request parameter and displays the marksheet for the student.

WTAD Practical - 16
Assume that the information regarding the marks for all the subjects of a student in
the last exam are available in a database, Develop a Servlet which takes the
enrollment number of a student as a request parameter and displays the marksheet for the student.
index.html


<HTML>
<HEAD>
<TITLE>WTAD.practical-16 @iAmLearningHere </TITLE>

</HEAD>
<BODY bgcolor="YellowGreen">
<h3> Result  </h3>
<hr>
<form name="frm1" action="display">
Enter Enrolment No :: <input type="text" name="en"> 
<input type="submit" Value="Get Result"">
</form>
</BODY>
</HTML>


WEB-INF/web.xml
<web-app>
<servlet>
<servlet-name>s16</servlet-name>
<servlet-class>DB</servlet-class>
</servlet>
<!-- Servlet Mapping -->
<servlet-mapping>
<servlet-name>s16</servlet-name>
<url-pattern>/display</url-pattern>
</servlet-mapping>
</web-app>


WEB-INF/classes/Syllabus.java


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

import java.sql.*;

public class DB extends HttpServlet
{
public void doGet( HttpServletRequest request,HttpServletResponse response ) throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();

//String en = request.getParameter("en");
String en = request.getParameter("en");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:DSN1");

String query = "select * from Marks where EnrolmentNo=?";
PreparedStatement ps=con.prepareStatement(query);
ps.setString(1, en);
    ResultSet rs= ps.executeQuery();

out.println("<HTML>" + 
"<HEAD><TITLE>WTAD.practical-16 @iAmLearningHere</TITLE></HEAD>" +
"<body bgcolor=YellowGreen>");
out.println("<h3>Enrolment No :: </h3>"+ en +"<br>");
out.println("<table border=1>");
out.println("<tr><th>Subject1</th><th>Subject2</th><th>Subject3</th></tr>");

if( rs.next() )
{
out.println("<tr><td>" + rs.getInt(3) + "</td><td> " + rs.getInt(4) + " </td><td>" + rs.getInt(5)+ "</td></tr>");
}
out.println("</table><a href=index.html>Home</a></body></HTML>");
}
catch( Exception e )
{
out.println(e);
}
}
}

Preview




How to Run?
> Start Apache Server
> Start localhost and open program folder
> Enter Enrolment No and submit

For all WTAD programs wtad-pra cticals.html
To get all programs in your inbox.Enter your email

Kindly Bookmark and Share it:

0 comments :

Post a Comment

Any Query ? any suggestion ? comment here

 

Recent Post

Recent Comments

© 2010 IamLearningHere Template by MBT