Showing posts with label internet programming lab manual. Show all posts
Showing posts with label internet programming lab manual. Show all posts

Tuesday, February 5, 2013

Displaying book details using XML and XSLT


Displaying book details using XML and XSLT


DISPLAYING BOOK DETAILS USING XML AND XSLT


Aim:
         To write XML program to display book details with XSL

Algorithm:
1. Create an XSL page
2. Set styles for an XML file and save the file with extension .xsl
3. Create another file and include XML tags
4. Write code to link the XSL file
5. Save the file with extension .xml
6. Run the XML file
7. Verify the result

Simple.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="simple.xsl"?>
<books_menu>
<book>
<name>
Computer Architecture </name>
<price> 234.56
</price>
<description>
Computer Is an electronic device
</description>
<pages>456
</pages>
</book>
<book>
<name>
Computer Organisation </name>
<price> 234.56
</price>
<description>
Computer has input and output devices
</description>
<pages>456
</pages>
</book>
</books_menu>

simple.xsl:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xlmns="http://www.w3.org/1999/xhtml">
<body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
<xsl:for-each select="books_menu/book">
<div style="background-color:teal;color:white;padding:4px">
<span style="font-weight:bold">
<xsl:value-of select="name"/>
</span>
</div>
<div style="margin-left:20px;margin-bottom:1cm;font-size:10pt">
<xsl:value-of select="description"/>
<span style="font-style:italic">
<xsl:value-of select="pages"/>
(pages in book)
</span>
</div>
</xsl:for-each>
</body>
</html>






OUTPUT SCREENSHOTS



Displaying student marklist using Java Server Pages


Displaying student marklist using Java Server Pages



DISPLAYING STUDENT MARK LIST USING JSP

AIM:
      To create a three tier application for displaying student mark list using JSP and database.

ALGORITHM:
1.       Design the HTML page (stud.html) with the following
a)   Create a form to get the input (Register Number) from the user.
b)   Set the URL of the server (marklist.jsp) as the value of the action attribute.
c)   Use submit button to invoke the server and send the form data to the server.
2.       Create the JSP file with the following
a)    Read the parameter value (Register Number) from the form by using the method getParameter().
b)    Server retrieves the details from the database table with respect to the form input.
c)    Server displays the mark list to the client as the response.

marklist.jsp:

<%@ page contentType="text/html" language="java" import="java.sql.*"%>
<html>
<head>
<title>Three Tier Application</title>
<style type="text/css">
  body{color:blue;font-family:courier;text-align:center}
</style>
</head>
<body>
<h2>EXAMINATION RESULT</h2><hr/>
<%
String str=request.getParameter("regno");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:markDS");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM markTab WHERE rno="+str);
while(rs.next())
{
%>
Register No:<%=rs.getObject(1)%><br/>
Name:<%=rs.getObject(2)%><br/>
<table border="1">
<th>SUBJECT</th><th>Mark</th>
<tr><td>Network Programming and Management</td><td><%=rs.getObject(3)%></td></tr>
<tr><td>Object Oriented Analysis and Design</td><td><%=rs.getObject(4)%></td></tr>
<tr><td>Cryptography and Network Security</td><td><%=rs.getObject(5)%></td></tr>
<tr><td>Embedded Systems</td><td><%=rs.getObject(6)%></td></tr>
<tr><td>Web Technology</td><td><%=rs.getObject(7)%></td></tr>
<tr><td>Software Requirement and Engineering</td><td><%=rs.getObject(8)%></td></tr>
</table>
<%
}
%>
<br/>
<a href="stud.html">Back</a>
</body>
</html>

stud.HTML:

<html>
<head>
<title>Three Tier Application</title>
<style type="text/css">
  body{color:blue;font-family:courier;text-align:center}
</style>
</head>
<body>
<h2>EXAMINATION RESULT</h2><hr/>
<form name="f1" method"GET" action="marklist.jsp">
Enter Your Reg.No:
<input type="text" name="regno"/><br/><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="SUBMIT"/>
</form>
</body>
<html>


DATABASE






OUTPUT SCREENSHOTS



Online Eamination using JSP and Databases


Online Eamination using JSP and Databases




Download Source code



Download Database file 


index.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Welcome to Online Examination</title>
    </head>
    <body bgcolor="cyan">
        <form name="index" action="exam.jsp" method="post">
        <center><h1><span><font color="red">Welcome to Online Examination</font></span></h1>
        <br>
        <h2><u><span><font color="blue">Instructions to the Candidates</font></span></u></h2>
        <br><h3><ol><li>Fill the correct Registration number.</li>
        <br><li>Enter your name.</li>
        <br><li>Read the questions carefully.</li>
        <br><li>No negative marking.</li></ol></h3>
      
        <br>
        <b>Enter your Register number</b>
        <input type="text" name="txt_reg">
        <b>Enter your Name</b>
        <input type="text" name="txt_name"><br><br>
        <input name ="submit" value="Submit" type="submit"/>
        </center>
        </form>
    </body>
</html>


exam.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Examination Panel</title>
    </head>
    <body bgcolor="cyan">
        <%@ page language="java" %>
<%@ page import ="java.sql.*" %>
<%
String reg= request.getParameter("txt_reg");
String name = request.getParameter("txt_name");
out.println("<h2>Welcome"   name   "...Your Register number is "   reg   "!!</h2><br><br><br>");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sTable = "exam";
String sSql = "SELECT * FROM "   sTable   "";
String sDBQ = "C:/Users/A/Documents/NetBeansProjects/Online Examination/exam.mdb";

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="   sDBQ   ";DriverID=22;READONLY=true";
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
cn = DriverManager.getConnection( database ,"","");
st = cn.createStatement();
rs = st.executeQuery( sSql );
ResultSetMetaData rsmd = rs.getMetaData();
String s1,s2,s3,s4;
int i=1;
while(rs.next())
{

out.println("<form name='exam' action='report.jsp' method='post'><b>" i " . "   rs.getString(1)   "</b><br><br>");
s1 = rs.getString(2);
s2 = rs.getString(3);
s3 = rs.getString(4);
s4 = rs.getString(5);
out.println("<input type=radio name=opt" i " value=" s1 " CHECKED>"  s1  " <br><br>");
out.println("<input type=radio name=opt" i " value=" s2 ">"   s2  "<br><br>");
out.println("<input type=radio name=opt" i " value=" s3 ">"   s3  "<br><br>");
out.println("<input type=radio name=opt" i " value=" s4 ">"   s4  "<br><br>");
i  ;
}
out.println("<input name ='submit' value='Submit' type='submit'/>");
/*int n = rsmd.getColumnCount();
out.println( "<table border=1 cellspacing=3><tr>" );
for( int i=1; i<=n; i   ) // Achtung: erste Spalte mit 1 statt 0
out.println( "<th>"   rsmd.getColumnName( i )   "</th>" );
while( rs.next() )
{
out.println( "</tr><tr>" );
for( int i=1; i<=n; i   ) // Achtung: erste Spalte mit 1 statt 0
out.println( "<td nowrap>"   rs.getString( i )   "</td>" );
}
out.println( "</tr></table>" );*/
}
  finally {
try { if( null != rs ) rs.close(); } catch( Exception ex ) {}
try { if( null != st ) st.close(); } catch( Exception ex ) {}
try { if( null != cn ) cn.close(); } catch( Exception ex ) {}
}

%>
        
    </body>
</html>

report.jsp

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Exam Report</title>
    </head>
    <body bgcolor="cyan">
        <center><h1>Your Report Card</h1></center>
 <%@ page language="java" %>
<%@ page import ="java.sql.*" %>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String sTable = "exam";
String sSql = "SELECT * FROM "   sTable   "";
String sDBQ = "C:/Users/A/Documents/NetBeansProjects/Online Examination/exam.mdb";

String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="   sDBQ   ";DriverID=22;READONLY=true";
Connection cn = null;
Statement st = null;
ResultSet rs = null;
try {
cn = DriverManager.getConnection( database ,"","");
st = cn.createStatement();
rs = st.executeQuery( sSql );
ResultSetMetaData rsmd = rs.getMetaData();
String s1,s2,s3,s4;
int i=1;
int correct=0,incorrect=0,total=0;
out.println("<h2><br><br><center><table border=1 cellpadding=2 cellspacing=2><tr><th>Question</th><th>Your Answer</th><th>Correct Answer</th><th>Status</th></tr>");
while(rs.next())
{
total  ;
s1 = rs.getString(1);
s2 = request.getParameter("opt" i);
s3 = rs.getString(6);
if(s2.equals(s3))
{
    s4="Correct";
    correct  ;
}
else
{
    s4="Incorrect";
    incorrect  ;
}    
out.println("<tr><td>" s1 "</td><td>" s2 "</td><td>" s3 "</td><td>" s4 "</td></tr>");
i  ;
}
out.println("</table><br><br><table><b><tr><td>Correct Answers</td><td>" correct "</td></tr>");
out.println("<tr><td>Incorrect Answers</td><td>" incorrect "</td></tr>");
out.println("<tr><td>Total Questions</td><td>" total "</td></tr></table></b></center></h2>");

}
  finally {
try { if( null != rs ) rs.close(); } catch( Exception ex ) {}
try { if( null != st ) st.close(); } catch( Exception ex ) {}
try { if( null != cn ) cn.close(); } catch( Exception ex ) {}
}

%>
      
    </body>
</html>





Screenshots


index.jsp


exam.jsp


report.jsp


Tuesday, January 29, 2013

DISPLAYING CRICKET PLAYERS PROFILE USING AJAX

      
        DISPLAYING CRICKET PLAYERS PROFILE USING AJAX
 AIM:
      To write a program using AJAX for displaying cricket players profile.

ALGORITHM:
    Step 1: Create an XHTML document (AjaxDemo.html) with the following.
    Step 2: Insert some images of cricket players.
    Step 3: Call the function getContent() with respect to the onmouseover event. The function accepts an argument that is the URL of another page contains the information about the player.
    Step 4: Call the function clearContent() with respect to the onmouseout event.
    Step 5: Within this XHTML document, insert AJAX based JavaScript code with the following.
     i)Create the object for ActiveXObject (for older versions of browsers such as IE5 and IE6).
      ii) Create the object for XMLHttpRequest (for modern browsers such as IE7+, Firefox, Chrome, Safari, and Opera).
     Step 6: AJAX send the request with the use of send() and open() methods.
    Step 7: Receive the response with the use of responseText Property.
    Step 8: AJAX Call the function diplayProfile() with respect to the event onreadystatechange.
      
PROGRAM:
AjaxDemo.html
<html>
<head>
<title>Ajax Demo...</title>
<style type="text/css">
  .box{border:1px solid blue;padding:10px}
</style>
<script type="text/javascript">
var req;
function getContent(url)
{
 if(window.ActiveXObject)
 {
  req=new ActiveXObject("Microsoft.XMLHTTP");
 }
 else if(window.XMLHttpRequest)
 {
  req=new XMLHttpRequest();
 }
 req.onreadystatechange=diplayProfile;
 req.open('POST',url,true);
 req.send(null);
}
function diplayProfile()
{
 if(req.readyState==4)
 {
  document.getElementById('contentArea').innerHTML=req.responseText;
 }
}
function clearContent()
{
 document.getElementById('contentArea').innerHTML='';
}
</script>
</head>
<body bgcolor="cyan">
<h1>Mouse over the image for More Information</h1>
<img src="sachin.jpg" height="95" width="80" onmouseover='getContent("sachin.html")' onmouseout='clearContent()'/>
<img src="dravid.jpg" height="95" width="80" onmouseover='getContent("dravid.html")' onmouseout='clearContent()'/>
<img src="kohli.jpg" height="95" width="80" onmouseover='getContent("kohli.html")' onmouseout='clearContent()'/>
<img src="raina.jpg" height="95" width="80" onmouseover='getContent("raina.html")' onmouseout='clearContent()'/>
<img src="yuvi.jpg" height="95" width="80" onmouseover='getContent("yuvi.html")' onmouseout='clearContent()'/>
<img src="veeru.jpg" height="95" width="80" onmouseover='getContent("veeru.html")' onmouseout='clearContent()'/>
<img src="dhoni.jpg" height="95" width="80" onmouseover='getContent("dhoni.html")' onmouseout='clearContent()'/>
<div class="box" id="contentArea"/>
</body>
</html>
sachin.html
<html>
<body>
<b>Full name:</b> Sachin Ramesh Tendulkar<br/><br/>
<b>Born:</b> April 24, 1973, Bombay (now Mumbai), Maharashtra<br/><br/>
<b>Major teams:</b> India, Asia XI, Mumbai, Mumbai Indians, Yorkshire<br/><br/>
<b>Nickname:</b> Tendlya, Little Master<br/><br/>
<b>Playing role:</b> Top-order batsman<br/><br/>
<b>Batting style:</b> Right-hand bat<br/><br/>
<b>Bowling style:</b> Right-arm offbreak, Legbreak googly
</body></html>
dravid.html
<html>
<body>
<b>Full name:</b> Rahul Sharad Dravid<br/><br/>
<b>Born:</b> January 11, 1973, Indore, Madhya Pradesh <br/><br/>
<b>Major teams:</b> India, Scotland, Asia XI, ICC World XI, Karnataka, Kent,
Marylebone Cricket Club, Rajasthan Royals, Royal Challengers Bangalore<br/><br/>
<b>Nickname:</b> The Wall<br/><br/>
<b>Playing role:</b> Top-order batsman<br/><br/>
<b>Batting style:</b> Right-hand bat<br/><br/>
<b>Bowling style:</b> Right-arm offbreak
</body>
</html>
kohli.html
<html>
<body>
<b>Full name:</b> Virat Kohli<br/><br/>
<b>Born:</b>November 5, 1988, Delhi<br/><br/>
<b>Major teams:</b>India, Delhi, India Red, India Under-19s, Royal Challengers Bangalore<br/><br/>
<b>Playing role:</b>Middle-order batsman<br/><br/>
<b>Batting style:</b>Right-hand bat<br/><br/>
<b>Bowling style:</b>Right-arm medium
</body>
</html>

raina.html
<html>
<body>
<b>Full name:</b> Suresh Kumar Raina<br/><br/>
<b>Born:</b>November 27, 1986, Muradnagar, Ghaziabad, Uttar Pradesh<br/><br/>
<b>Major teams:</b>India, Chennai Super Kings, India Blue, India Under-19s, Indian Board President's XI, Rajasthan Cricket Association President's XI, Uttar Pradesh, Uttar Pradesh Under-16s<br/><br/>
<b>Playing role:</b>Middle-order batsman<br/><br/>
<b>Batting style:</b>Left-hand bat<br/><br/>
<b>Bowling style:</b> Right-arm offbreak
</body>
</html>
yuvi.html
<html>
<body>
<b>Full name:</b>Yuvraj Singh<br/><br/>
<b>Born:</b>December 12, 1981, Chandigarh<br/><br/>
<b>Major teams:</b>India, Asia XI, Kings XI Punjab, Pune Warriors, Punjab, Yorkshire<br/><br/>
<b>Playing role:</b>Middle-order batsman<br/><br/>
<b>Batting style:</b>Left-hand bat<br/><br/>
<b>Bowling style:</b>Slow left-arm orthodox
</body>
</html>
veeru.html
<html>
<body>
<b>Full name:</b>Virender Sehwag<br/><br/>
<b>Born:</b>October 20, 1978, Delhi<br/><br/>
<b>Major teams:</b>India, Asia XI, Delhi, Delhi Daredevils, ICC World XI, India Blue, Leicestershire, Rajasthan Cricket Association President's XI<br/><br/>
<b>Playing role:</b>Top-order batsman<br/><br/>
<b>Batting style:</b>Right-hand bat<br/><br/>
<b>Bowling style:</b>Right-arm offbreak
</body>
</html>
dhoni.html
<html>
<body bgcolor="cyan">
<b>Full name:</b> Mahendra Singh Dhoni<br/><br/>
<b>Born:</b>July 7, 1981, Ranchi, Bihar (now Jharkhand)<br/><br/>
<b>Major teams:</b>India, Asia XI, Bihar, Chennai Super Kings, Jharkhand<br/><br/>
<b>Playing role:</b>Wicketkeeper batsman<br/><br/>
<b>Batting style:</b>Right-hand bat<br/><br/>
<b>Bowling style:</b>Right-arm medium
</body>
</html>



RESULT:
       Thus the program using AJAX for displaying cricket players profile is written and output is verified.
                  Thus the web services and database is implemented and output is verified.