You are on page 1of 30

Prepared By : Prof. J.

Hajiram Beevi, Jamal Mohamed College Page 1

1. Write a XML program for job listing in HRML.


Aim:
To write a XML program for job listing in HRML.
Procedure:
1. Create an XML file named as job.xml
2. Create the user defined tags associated with job listing and display the output in XML format.
Coding:
job.xml
<?xml version="1.0"?>
<JobPositionPosting>
<JobPositionPostingId>Job ID:25740</JobPositionPostingId>
<HiringOrg>
<HiringOrgName>Organization Name:John Wiley &amp; sons</HiringOrgName>
<WebSite>WebSite Address:http://www.wiley.com</WebSite>
<Industry><SummaryText>Publishing</SummaryText></Industry>
<Contact>
<PersonName>
<GivenName>Mara</GivenName>
<FamilyName>Cordal</FamilyName>
</PersonName>
</Contact>
</HiringOrg>
<JobPositionInformation>
<JobPositionTitle>Editor</JobPositionTitle>
<JobPositionDescription>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 2

<JobPositionPurpose>
Working in our scientific publications
</JobPositionPurpose>
<JobPositionLocation>
<LocationSummary>
<Municipality>Hoboken</Municipality>
<Region>NJ</Region>
</LocationSummary>
</JobPositionLocation>
<Classification>
<DirectHireOrContract>
<DirectHire/>
</DirectHireOrContract>
<Duration>
<Regular/>
</Duration>
</Classification>
<CompensationDescription>
<Pay>
<SalaryAnnual currency="USD">60,000</SalaryAnnual>
</Pay>
</CompensationDescription>
</JobPositionDescription>
<JobPositionRequirements>
<QualificationsRequired>
<Qualification type="education">College</Qualification>
<Qualification type="experience" yearsOfExperience="3-5">
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 3

Book acquisitions
</Qualification>
<Qualification type="skill">
Electrical Engineering
</Qualification>
<Qualification type="skill">
Telecommunications
</Qualification>
</QualificationsRequired>
<SummaryText>
In depth knowledge of the markets and subject areas assigned
</SummaryText>
</JobPositionRequirements>
</JobPositionInformation>
<HowToApply distribute="external">
<ApplicationMethods>
<ByEmail>
<E-mail>opportunities@wiley.com</E-mail>
<SummaryText>Please put the job title,department, location and reference number
</SummaryText>
</ByEmail>
<ByFax>
<PersonName>
<GivenName>Attn:</GivenName>
<FamilyName>Human Resources</FamilyName>
</PersonName>
<FaxNumber>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 4

<AreaCode>201</AreaCode>
<TelNumber>748-6049</TelNumber>
</FaxNumber>
</ByFax>
<ByMail>
<PostalAddress>
<CountryCode>US</CountryCode>
<PostalCode>07030</PostalCode>
<Region>NJ</Region>
<Municipality>Hoboken</Municipality>
<DeliveryAddress>
<AddressLine>River Street</AddressLine>
</DeliveryAddress>
</PostalAddress>
</ByMail>
</ApplicationMethods>
<SummaryText>
Please be sure to indicate the position and job number
</SummaryText>
</HowToApply>
<EEOStatement>
John wiley is an equal opportunity employer
</EEOStatement>
<NumberToFill>1</NumberToFill>
</JobPositionPosting>
Output:

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 5

Result:
Thus the XML program for job listing was developed and executed successfully.
2. Write a JavaScript code block, which checks the contents entered in a forms text
element. If the text entered is in the lower case, convert to upper case.
Aim:
To develop a javascript program to perform an upper case conversion.
Procedure:
1. Create an html page named as upper.html
2. Within the script tag, define a function called as upper() to convert the given string to upper
case.
3. Within the body tag, get the string from the user and display a button to call the upper()
method.
Coding:
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 6

upper.html
<html><head>
<script type = "text/javascript">
function upper()
{
var upper = document.form1.string.value.toUpperCase();
document.form1.string.value = upper;
}
</script></head><body>
<form name = "form1">
<table><tr><td>Enter String</td><td><input type = "text" name = "string" /></td></tr>
<tr><td><input type = "button" value = "upper" onclick = "upper()"></td></tr>
</table></form></body></html>
Output

Result:
Thus the javascript program to perform an upper case conversion was successfully executed and
verified.
3. Write a JavaScript code block, which validates a username and password.
a) If either the name or password field is not entered display an error message.
b) The fields are entered do not match with default values display an error message.

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 7

c) If the fields entered match, display the welcome message.


Aim:
To develop a javascript coding to validate the username and password.
Procedure:
1. Create an html page named as pass.html
2. Within the script tag, define a function called as validateForm() to validate the given user
name and password.
3. Within the body tag, get the user name and password from a user and display the button to call
the validateForm() method.
Coding:
pass.html
<html>
<head>
<script>
function validateForm() {
var x = document.forms["myForm"]["uname"].value;
var y = document.forms["myForm"]["pass"].value;
if ((x == null || y== null) || (x == "" || y=="")) {
alert("User name and password must be filled out");
return false;
}
else if((x=="hajira")&&(y==111))
{
alert("Welcome to world of coding");
}
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 8

else
{
alert("Wrong user name and password");
}
}
</script>
</head>
<body>
<form name="myForm" action=""onsubmit="return validateForm()" method="post">
<center><h2>User Registration</h2>
User name: <input type="text" name="uname"><br><br>
Password : <input type="password" name="pass"><br><br>
<input type="submit" value="Submit">
</center>
</form>
</body>
</html>

Output:

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 9

Result:
Thus the javascript program to validate the username and password was successfully executed
and verified.
4. Write a JavaScript code to display the current date and time in a browser.
Aim:
To develop a javascript code to display the current date and time in a browser.
Procedure:
1. Create an html page named astiming.html
2. Within the script tag, call the built in functions getDate(), getMonth(), getFullYear(),
getHours(), getMinutes() to print the current date and time in a browser.

Coding:
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 10

timing.html
<html>
<head>
<script type = "text/javascript">
var now = new Date();
now.setDate(now.getDate());
var date = now.getDate();
var month = now.getMonth()+1;
var year = now.getFullYear();
var hour = now.getHours();
var minutes = now.getMinutes();
if(hour > 12 || minutes > 0){
meridian = 'PM';
}
else {
meridian = 'AM';
}
if (minutes < 10) {
minutes = "0"+min;
};
var time = hour+":"+ minutes +" "+meridian;
var MonthDateYearTime = month + "/" + date + "/" + year + " " + time;
document.write( MonthDateYearTime.bold() );
</script>
</head>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 11

Output

Result
Thus the javascript code to display the current date and time in a browser was successfully
executed and verified.
5. Write a JSP program for user authentication
Aim:
To develop a JSP program for user authentication.
Procedure:
1. Create an html page named as main1.html
2. Within the body tag, get the student roll number and password and display the button to
submit the values.
3. Create a JSP file named as authenticate.jsp and LoginErrorPage.jsp.
4. Get the submitted values from main1.html through the getParameter() method.
5. Validate the submitted values with the default values, if it matches, display the welcome
message. Otherwise, exception message is shown.
Coding:
main1.html
<html>
<body>
<form name="f1" action="authenticate.jsp">
<marquee> JAMAL MOHAMED COLLEGE </marquee>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 12

<br><br>
<table cellspacing=5 cellpadding=5 bgcolor=#959999 colspan=2 rowspan=2 align="center">
<tr><td> Student Authentication Form</td></tr>
<tr><td>Enter Student Roll Number :</td>
<td><input type=text name="unum"></td></tr>
<tr><td>Enter Password: </td>
<td><input type=password name="password"></td></tr>
</table>
<br><table align="center"><tr><td><input type="submit" value=" Login " ></td>
<td><input type="Reset" value=" Cancel " ></td></tr>
</table></font></form></body></html>
Output:

authenticate.jsp
<%@ page errorPage="LoginErrorPage.jsp" %>
<html>
<body>
<%
String user=request.getParameter("unum");
int rollNum=Integer.parseInt(user);
String pass=request.getParameter("password");
if( rollNum== 111 && pass.equals("Hajira")){
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 13

out.println("Welcome to Jamal Mohamed College");


%>
<br><br>
<%
out.println("Login Successful"); }
else {
out.println("Login Unsuccessful"); }
%>
</body></html>
Output:

LoginErrorPage.jsp
<%@ page isErrorPage="true" %>
<html>
<body>
<h3>An exception has occurred</h3>
<table><tr><td>Exception Class:</td>
<td><%= exception.getClass() %></td></tr>
<tr><td>Message:</td>
<td><%= exception.getMessage() %></td></tr></table>
<br>
To go to login page again, click Login Page button
<form name="f2" action="main.html">
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 14

<input type="submit" name="button1" value="Login Page">


</form></body></html>
Result:
Thus the JSP program for user authentication was successfully developed and executed.
6. Write a JSP program for a simple shopping cart.
Aim:
To develop a JSP program to prepare a simple shopping cart.
Procedure:
1. Create a JSP file named as index.jsp. In this file, get the name and value of the items using
request.getParameterNames() method and set the session object.
2. Create another JSP file named as carts.jsp. In this file, just display the items added to the
cart using session.getAttributeNames() method.
3. Create the next JSP file named as remove.jsp. In this file, just remove the items already
added to the cart using session.removeAttribute() method.
Coding:
index.jsp
<html><head><title>Shopping cart</title></head>
<body>
<jsp:declaration>
java.util.Enumeration parms;
java.util.Enumeration values;
</jsp:declaration>
<jsp:scriptlet>
parms = request.getParameterNames();
values = request.getParameterNames();
while(parms.hasMoreElements()) {
String name = (String) parms.nextElement();
String value = (String) values.nextElement();
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 15

session.setAttribute(name, value);
}
</jsp:scriptlet>
<img src="images/add.jpg" onclick="document.location='index.jsp'">
<img src="images/remove.jpg" onclick="document.location='remove.jsp'">
<img src="images/cart.jpg" onclick="document.location='carts.jsp'">
<h2>Add to shopping cart</h2>
<form method="get" action="index.jsp">
<table><tr><td><input type="checkbox" <% if (session.getAttribute("scissors") != null)
out.print("unchecked"); %> name="scissors"></td>
<td>Scissors</td>
</tr><tr><td><input type="checkbox" <% if (session.getAttribute("book") != null)
out.print("unchecked"); %> name="book"></td>
<td>Book</td>
</tr><tr>
<td><input type="checkbox" <% if (session.getAttribute("pen") != null)
out.print("unchecked"); %> name="pen"></td><td>Pen</td>
</tr></table>
<br><br><input type="submit" value="submit"></form></body></html>

Output:

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 16

carts.jsp
<html><head><title>Shopping cart</title></head>
<body>
<img src="images/add.jpg" onclick="document.location='index.jsp'">
<img src="images/remove.jpg" onclick="document.location='remove.jsp'">
<img src="images/cart.jpg" onclick="document.location='carts.jsp'">
<h2>The shopping cart</h2>
<jsp:scriptlet><![CDATA[
java.util.Enumeration content = session.getAttributeNames();
while (content.hasMoreElements()) {
out.println(content.nextElement());
out.println("<br>");
}
]]></jsp:scriptlet></body></html>
Output:

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 17

remove.jsp
<html><head><title>Shopping cart</title></head>
<body>
<jsp:declaration>
java.util.Enumeration parms;
</jsp:declaration>
<jsp:scriptlet>
parms = request.getParameterNames();
while(parms.hasMoreElements()) {
String name = (String) parms.nextElement();
session.removeAttribute(name);
}
</jsp:scriptlet>
<img src="images/add.jpg" onclick="document.location='index.jsp'">
<img src="images/remove.jpg" onclick="document.location='remove.jsp'">
<img src="images/cart.jpg" onclick="document.location='carts.jsp'">
<h2>Remove items from cart</h2>
<form method="get" action="remove.jsp">
<table>
<% if (session.getAttribute("scissors") != null) { %>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 18

<tr><td><input type="checkbox" name="scissors"></td><td>Scissors</td></td></tr>


<% } %>
<% if (session.getAttribute("book") != null) { %>
<tr><td><input type="checkbox" name="book"></td><td>Book</td></td></tr>
<% } %>
<% if (session.getAttribute("pen") != null) { %>
<tr><td><input type="checkbox" name="pen"></td><td>Pen</td></td></tr>
<% } %></table><br><br><input type="submit" value="submit"></form></body></html>
Output:

Result:
Thus the JSP program for shopping cart was successfully developed and executed.
7. Write a JSP program to prepare bio data and store it in database
Aim:
To develop a JSP program to prepare the bio data and store it in access database.

Procedure:
1. Create a JSP file named as reg.jsp.

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 19

2. Within the body tag, get the name, address, phone number, sex, nationality, age and email ID
and display the button to submit the values.
3. Create another JSP file named as display.jsp. In this file, import the data base relevant
classes using import statement.
4. Create the database reg.accdb with the fields sname,address,phone,sex,nationality,age and
email.
5. Establish a connection to the database using DriverManager.getConnection() method.
6. Perform insert operation to store the values into the database which are posted from the
previous form.
7. Finally perform the selection operation to display the retrieved values from the database.
Coding:
reg.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Bio-Data</title>
</head>
<body>
<h1><B><center>BIO DATA</center></B></h1>
<form action="display.jsp" method="POST">
<CENTER><table border="1">
<tbody><tr><td>Name</td>
<td><input type="text" name="c1" value="" size="30" /></td> </tr>
<tr><td>Address</td><td><input type="text" name="c2" value="" size="30" /></td></tr>
<tr><td>Phone No.</td><td><input type="text" name="c3" value="" size="30" /></td></tr>
<tr><td>Sex</td><td><input type="text" name="c4" value="" size="30" /></td></tr>
<tr><td>Nationality</td><td><input type="text" name="c5" value="" size="30" /></td></tr>
<tr><td>Age</td><td><input type="text" name="c6" value="" size="30" /></td></tr>
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 20

<tr><td>Email ID</td><td><input type="text" name="c7" value="" size="30" /></td></tr>


<tr><td></td><td><input type="submit" value="submit" name="b1" /></td></tr></tbody>
</table></CENTER></form></body></html>
Output:

display.jsp
<%@page import ="java.sql.*"%>
<%@page import =" java.util.*"%>
<%@page import =" java. io.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>JSP Page</title></head><body>
<h1>registration record!</h1>
<%
try {
String url="jdbc:odbc:reg";
Connection c=DriverManager.getConnection("jdbc:ucanaccess://D:reg.accdb");
Statement st=c.createStatement();
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 21

PreparedStatement pst=c.prepareStatement("insert into


registration(sname,address,phone,sex,nationality,age,email) values( ?, ?, ?, ?, ?, ?, ?)");
pst.clearParameters();
pst.setString(1,request.getParameter("c1"));
pst.setString(2,request.getParameter("c2") );
pst.setString(3,request.getParameter("c3") );
pst.setString(4,request.getParameter("c4") );
pst.setString(5,request.getParameter("c5") );
pst.setString(6,request.getParameter("c6") );
pst.setString(7,request.getParameter("c7") );
int i= pst.executeUpdate();
if(i>0)
{
out.println("Record Saved");
ResultSet rs=st.executeQuery("Select * from registration");
out.print("<br/>");
out.print("<table border=4>");
out.print("<tr><th>Name</th><th>Address</th><th>Phone</th><th>Sex</th>><th>Nationality
</th><th>Age</th><th>Email</th></tr>");
while(rs.next())
{
out.print("<tr bgcolor=pink>");
out.print("<td>");
out.print(rs.getString(7));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(1));
out.print("</td>");
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 22

out.print("<td>");
out.print(rs.getString(2));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(3));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(4));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(5));
out.print("</td>");
out.print("<td>");
out.print(rs.getString(6));
out.print("</td>");
out.print("</tr>");
}out.print("</table>");}
else{out.println("Record Not Saved");}}
catch(Exception e)
{}
finally {
out.close();
}%></body></html>
Output:

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 23

Result:
Thus the JSP program for database storage was successfully developed and executed.
8. Write an ASP Program using Response and Request Object.
Aim:
To develop an ASP program using Response and Request object.
Procedure:
1. Create an ASP file named as request.asp
2. Within the body tag, get the firstname and lastname of the user and display the button to
submit the values.
3. Get the posted values of the form using Request.QueryString() method and write the output to
the browser using Response.Write() method.
Coding:
request.asp
<%@language="javascript"%>
<html><body>
<a href="request.asp?color=green">Example</a>
<%var str=Request.QueryString;
Response.Write(str);%>
<form action="request.asp" method="get">
First name: <input type="text" name="fname"><br />
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 24

Last name: <input type="text" name="lname"><br />


<input type="submit" value="Submit">
</form></body></html>
Output:

Result:
Thus the ASP program using Response and Request object was successfully developed and
executed.
9. Write an ASP Program using AdRotator Component.
Aim: To develop an ASP program to display various ads using AdRotator Component.
Procedure and Coding:
Step 1: Create the text file named as Advertisemens.txt which contains the details of images.
Coding:
REDIRECT T3.asp
WIDTH 500
HEIGHT 1000
BORDER 5
*
1.JPEG
http://www.coderewind.com/
NATURE
10
2.JPEG
http://www.microsoft.com/
BEAUTY
20
3.JPEG
http://www.google.com/
FLOWER
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 25

30
Step 2: Type the following code in the notepad and named it as T3.asp
Coding:
<HTML>
<HEAD>
<TITLE>AD ROTATOR</TITLE>
</HEAD>
<BODY BGCOLOR=FFFFFFF>
<%
set adrotator = Server.CreateObject("MSWC.AdRotator")
response.write(adrotator.GetAdvertisement("/Advertisements.txt"))
%>
</BODY>
</HTML>
Step 3: Run the program using http://localhost/T3.asp and it displays the output.
Result:
Thus the ASP program using AdRotator Component was successfully developed and executed.
10. Write an ASP program using database connectivity for students record.
Aim: To develop an ASP program to store and display the students record using MS Access
database.
Procedure and Coding:
Step 1: Create the database
To create a database your first need to open Microsoft Access and choose 'Blank Access
Database' from the starting menu. You will be prompted for a name for the database and where
you want it saved. Call the database 'student.mdb' and save it in the Inetpub directory.
select 'Create table in design view'.
You now need to create 5 fields for the database and select their data types.
Field 1 needs to be called 'Student_Name' and have the data type of 'text'. Also set this field as
the primary key.
Field 2 needs to be called 'Roll_Num' and have the data type of 'number'.
Field 3 needs to be called 'Sex' and have the data type of 'text'.
Field 4 needs to be called 'Age' and have the data type of 'number'.
Field 5 needs to be called 'Class' and have the data type of 'text'.
Once all the field's have been created and the data types and primary key set, save the table as
'Stud'.
Now the table has been created you need to enter some test data into the table.

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 26

Stud
Student_Name RollNum Sex

Age Class

Ahamed

105

Male

22 III MCA

Girija

103

Female 21 III MCA

Meena

101

Female 20 II MCA

Raj

104

Male

Vimala

102

Female 20 II MCA

21 III MCA

Successfully you created the database. Now you connect the database using Microsoft Data Link
File.
Step 2: Create Microsoft Data Link File
To create a Universal Data Link (.udl) file
1. Open Windows Explorer.
2. Select the folder in which you want to store the .udl file.
3. If you are running Windows 2000 or later, select New on the File menu, and choose Text
Document. A new file named New Text Document.txt appears in the directory. Rename
this file, removing all spaces and changing its file extension to .udl.
Note A warning that changing file extensions can cause files to become unusable might
appear. Disregard it.
If you are running Windows 98 and Windows NT systems with Microsoft Data Access
Components (MDAC) installed, right-click the right pane, or results pane, select New,
and choose Microsoft Data Link. A new file named New Microsoft Data
Link.udl appears in the directory. You can rename this file as sophos.udl.
To configure a universal data link (.udl) file
1. Double-click the universal data link (.udl) file.
The Data Link Properties dialog box opens, displaying the following
tabs: Provider, Connection, Advanced, and All. Choose Next to navigate from tab to
tab.
2. On the Provider tab, select a database provider Microsoft Jet.OLEDB.4.0.

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 27

3. On the Connection tab, either select the data source name (DSN)

4. Click test connection button to check the status of the connection. If it shows Test Connection
Succeeded, choose OK to save the connection string to the Universal Data Link (.udl) file.

Step 3: Type the following code in notepad and named it as sam.asp


sam.asp
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 28

<%
Dim cnnSimple ' ADO connection
Dim rstSimple ' ADO recordset
Set cnnSimple = Server.CreateObject("ADODB.Connection")
cnnSimple.Open
("Provider=Microsoft.Jet.OLEDB.4.0;Data
Server.MapPath("\student.mdb"))
Set rstSimple = cnnSimple.Execute("SELECT * FROM Stud")
%>
<P> Students Record </P>
<table border="1">
<tr>
<%for each x in rstSimple.Fields
response.write("<th align='left' bgcolor='#b0c4de'>" & x.name & "</th>")
next%>
</tr>
<%
Do While Not rstSimple.EOF
%>
<tr>
<td><%= rstSimple.Fields(0).Value %></td>
<td><%= rstSimple.Fields(1).Value %></td>
<td><%= rstSimple.Fields(2).Value %></td>
<td><%= rstSimple.Fields(3).Value %></td>
<td><%= rstSimple.Fields(4).Value %></td>
</tr>
<%
rstSimple.MoveNext
Loop
%>
</table>
<%
rstSimple.Close
Set rstSimple = Nothing
cnnSimple.Close
Set cnnSimple = Nothing
%>
Step 4: Save the program under /Inetpub/wwwroot directory.
Step 5: Run the program http://localhost/sam.asp

Source="

Output:
Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 29

&

Result:
Thus the ASP program using MS Access database was successfully developed and executed.

Prepared By : Prof. J. Hajiram Beevi, Jamal Mohamed College Page 30

You might also like