Sie sind auf Seite 1von 41

7208-HINDUSTHAN INSTITUTE OF TECHNOLOGY

COIMBATORE-32
DEPARTMENT OF INFORMATION TECHNOLOGY

IT6512 & WEB PROGRAMMING LABORATORY LAB MANUAL

PREPARED BY
P.NITHYA,AP /IT.

Ex. No :01
Date :
Aim:
Write a html program for Creation of web site with forms, frames, links, tables etc

Program:
Home.html
<html>
<head>
<title>Home</title>
</head>
<frameset rows="25%,*">
<frame src="frame1.html">
<frameset cols="25%,*">
<frame src="frame2.html" name="f2">
<frame src="frame3.html" name="f3">
</frameset>
</html>
Frame1.html
<html>
<head><title>frame1</title>
</head>
<body bgcolor="blue">
<h1 style="color.green;font-size:15pt">
<marquee bgcolor="#cccccc" loop="-1" scrollamount="6" width="100%"> HINDUSTHAN
INSTITUTE OF TECHNOLOG</marquee>
</h1>
</body>
</html>
Frame2.html
<html>
<head><title>frame2</title>
<style type="text/css">

h1
{
font-size:25pt;color:pink;
}
</style>
</head>
<body bgcolor="red">
<h1>click the link</h1>
<a href="intro.html" target=f3>Introduction</a><br>
<a href="dept.html" target=f3>Departments</a><br>
<a href="ad.html" target=f3>ADDRESS</a><br>
<a href="feed.html" target=f3>Feedback</a><br>
<a href="gall.html" target=f3>Gallery</a><br>
</body>
</html>
Frame3.html
<html>
<head><title>1st page</title>
<link rel="stylesheet" type="text/css" href="C:\Documents and
Settings\Administrator\Desktop\ab\css1.css"/>
</head>
<body bgcolor="tan">
<h2> <center>YOU ARE IN HOME PAGE</center></h2>
</body>
</html>
Intro.html
<html>
<head><title>intro</title>
</head>
<body bgcolor="black">
<font color=red>
<p>
Welcome to Kongunadu College of Engineering and Technology -Affiliated to Anna
University<br>
<br>
Hindusthan institute of Technology resolves to mould a human task force useful to the society
through transparent methods that lead to continuous improvement of the resources and state-ofthe-art methodologies conforming to recognized standards.
</p>
</font>
</body>
</html>
Ad.html
<html>
<head><title>ADDRESS</title>

</head>
<body bgcolor="black">
<p>
<font color=red>
Name:Hindusthan institute of Technology<br>
Location:coimbatore<br>
Contact No:8012505010<br>
Website: www.hindusthan.net<br>
</font>
</p>
</body>
</html>
Dept.html
<html>
<head><title>Departments</title>
</head>
<body>
<div align="center">
<table border=2>
<tr>
<th>Dept code</th>
<th>Dept name</th>
</tr>
<tr>
<td>01</td>
<td>CSE</td>
</tr>
<tr>
<td>02</td>
<td>ECE</td>
</tr>
<tr>
<td>03</td>
<td>EEE</td>
</tr>
<tr>
<td>04</td>
<td>IT</td>
</tr>
<tr>
<td>05</td>
<td>MECH</td>
</tr>
</table>
</div>
</body>

</html>
Feed.html
<html>
<head><title>feed</title>
</head>
<body bgcolor="black">
<p>
<font color=green>
To give your feedback mail to google_feedback@edu.in
</font>
</p>
</body>
</html>
Gall.html
<html>
<head><title>gall</title>
</head>
<body bgcolor="pink">
<p>
<font color=blue>
College Front View</font>
</p>
<img src="file:///d:/google.JPG" height="300" width="400"/>
</body>
</html>
SCREEN SHOTS:

Ex. No : 2
Date :
Aim :
Design a web site using HTML and DHTML. Use Basic text Formatting, Images
Program :
Ex2.html
<html>
<body>
<p>This text is normal.</p>
<p><b>This text is bold</b>.</p>
<p><strong>This text is strong</strong>.</p>
<p><i>This text is italic</i>.</p>
<p><em>This text is emphasized</em>.</p>
<h1>Headings 1</h1>
<h2>Headings 2</h2>
<h3>Headings 3</h3>
<h4>Headings 4</h4>
<h5>Headings 5</h5>
<h2>HTML <small>Small</small> Formatting</h2>
<h2>HTML <mark>Marked</mark> Formatting</h2>
<p>My favorite color is <del>blue</del> red.</p>
<p>My favorite <ins>color</ins> is red.</p>
<p>This is <sub>subscripted</sub> text.</p>
<p>This is <sup>superscripted</sup> text.</p>
<p>WWF's goal is to: <q>Build a future where people live in harmony with nature.</q></p>
<p>Here is a quote from WWF's website:</p>
<blockquote cite="http://www.worldwildlife.org/who/index.html">
For 50 years, WWF has been protecting the future of nature.
The world's leading conservation organization,
WWF works in 100 countries and is supported by
1.2 million members in the United States and
close to 5 million globally.
</blockquote>
<p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
<address>
Written by Jon Doe.<br>
Visit us at:<br>
Example.com<br>
Box 564, Disneyland<br>
USA
</address>

<bdo dir="rtl">This text will be written from right to left</bdo>


<p>To open a file, select:</p>
<p><kbd>File | Open...</kbd></p>
<samp>
demo.example.com login: Apr 12 09:10:17
Linux 2.6.10-grsec+gg3+e+fhs6b+nfs+gr0501+++p3+c4a+gr2b-reslog-v6.189
</samp>
<code>
var person = { firstName:"John", lastName:"Doe", age:50, eyeColor:"blue" }
</code>
<code>
<pre>
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"}
</pre>
</code>
<p>Einstein wrote:</p>
<p><var>E = m c<sup>2</sup></var></p>
<a href="http://www.kongunadu-engg.com">
<img src="Logo.jpg" alt="Kognuadu" width="200" height="142">
</a>
</body>
</html>
SCREEN SHOTS:

EX NO: 3
DATE :
AIM:
Create a script that asks the user for a name, then greets the user with "Hello" and the user name
on the page.
PROGRAM :
<html>
<body>
<p>Click the button.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var person = prompt("Please enter your name", "");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?";
}
}
</script>
</body>
</html>

Ex.No: 04
Date :
AIM : Create a script that collects numbers from a page and then adds them up and prints them to a blank
field on the page.
Program:
<html>
<head>
<script type="text/javascript">
function sum()
{
var a,b,c,d,e,f;
a=parseInt(document.getElementById("n1").value);
b=parseInt(document.getElementById("n2").value);
c=parseInt(document.getElementById("n3").value);
d=parseInt(document.getElementById("n4").value);
e=parseInt(document.getElementById("n5").value);
f=a+b+c+d+e;
document.getElementById("ans").value=f;
}
</script>
</head>
<body>
<table align="center">
<tr>
<td>Number 1</td>
<td><input type="text" id="n1"></td></tr>
<tr>
<td>Number 2</td>
<td><input type="text" id="n2"></td></tr>
<tr>
<td>Number 3</td>
<td><input type="text" id="n3"></td></tr><tr>
<td>Number 4</td>
<td><input type="text" id="n4"></td>
</tr>
<tr>
<td>Number 5</td>
<td><input type="text" id="n5"></td>
</tr>
<tr>
<td>Answer</td>
<td><input type="text" id="ans"></td>
</tr><tr>
<td>
<button onclick="sum()">Add</button>
</td>
</tr>
</table>
</body>
</html>

OUTPUT:

EX No : 05
Aim:
Create a script that prompts the user for a number and then counts from 1 to that number displaying only
the odd numbers.
Program:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var a=window.prompt("Enter the Number","");
for(var i=1; i<=a; i++)
{
if((i%2)!=0)
{
document.writeln("<br>"+i);
}
}
</script>
</head>
<body>
</body>
</html>
Output:

EX No: 06
Aim:
Create a script that will check the field in Assignment 1 for data and alert the user if it is blank. This script
should run from a button.
Program:

<!DOCTYPE HTML>
<html>
<head>
<title>user registration form validation using javascript with example</title>
<script>
function Submit(){
var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname = document.form.Name.value,
lname = document.form.LastName.value,
femail = document.form.Email.value,
freemail = document.form.enterEmail.value,
fpassword = document.form.Password.value,
fmonth = document.form.birthday_month.value,
fday = document.form.birthday_day.value,
fyear = document.form.birthday_year.value;
if( fname == "" )
{
document.form.Name.focus() ;
document.getElementById("errorBox").innerHTML = "enter the first name";
return false;
}
if( lname == "" )
{
document.form.LastName.focus() ;
document.getElementById("errorBox").innerHTML = "enter the last name";
return false;
}
if (femail == "" )
{
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the email";
return false;
}else if(!emailRegex.test(femail)){
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the valid email";
return false;
}

if (freemail == "" )
{
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "Re-enter the email";
return false;
}else if(!emailRegex.test(freemail)){
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "Re-enter the valid email";
return false;
}
if(freemail != femail){
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "emails are not matching,
re-enter again";
return false;
}
if(fpassword == "")
{
document.form.Password.focus();
document.getElementById("errorBox").innerHTML = "enter the password";
return false;
}
if (fmonth == "") {
document.form.birthday_month.focus();
document.getElementById("errorBox").innerHTML = "select the birthday
month";
return false;
}
if (fday == "") {
document.form.birthday_day.focus();
document.getElementById("errorBox").innerHTML = "select the birthday day";
return false;
}
if (fyear == "") {
document.form.birthday_year.focus();
document.getElementById("errorBox").innerHTML = "select the birthday year";
return false;
}
if(document.form.radiobutton[0].checked == false &&
document.form.radiobutton[1].checked == false){
document.getElementById("errorBox").innerHTML = "select your
gender";
return false;
}

if(fname != '' && lname != '' && femail != '' && freemail != '' && fpassword != ''
&& fmonth != '' && fday != '' && fyear != ''){
document.getElementById("errorBox").innerHTML = "form submitted
successfully";
}
}
</script>
</head>
<body>
<div id="description"></div>
<!--container start-->
<div id="container">
<div id="container_body">
<div>
<h2 class="form_title">User Registration Form Demo</h2>
<p class="head_para">Form Validated Using Javascript</p>
</div>
<!--Form start-->
<div id="form_name">
<div class="firstnameorlastname">
<form name="form" >
<div id="errorBox"></div>
<input type="text" name="Name" value="" placeholder="First Name"
class="input_name">
<input type="text" name="LastName" value="" placeholder="Last Name"
class="input_name" >
</div>
<div id="email_form">
<input type="text" name="Email" value="" placeholder="Your Email"
class="input_email">
</div>
<div id="Re_email_form">
<input type="text" name="enterEmail" value="" placeholder="Re-enter Email"
class="input_Re_email">
</div>
<div id="password_form">
<input type="password" name="Password" value="" placeholder="New Password"
class="input_password">
</div>
<!--birthday details start-->
<div>
<h3 class="birthday_title">Birthday</h3>
</div>
<div>
<select name="birthday_month" >
<option value="" selected >Month</option>

<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
&nbsp;&nbsp;
<select name="birthday_day" >
<option value="" selected>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>

<option value="31">31</option>
</select>
&nbsp;&nbsp;
<select name="birthday_year">
<option value="" selected>Year</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
</select>
</div>
<!--birthday details ends-->
<div id="radio_button">
<input type="radio" name="radiobutton" value="Female">
<label >Female</label>
&nbsp;&nbsp;&nbsp;
<input type="radio" name="radiobutton" value="Male">
<label >Male</label>
</div>
<div>
<p id="sign_user" onClick="Submit()">Sign Up </p>
</div>
</form>
</div>
<!--form ends-->
</div>
</div>
<!--container ends-->
</body>
</html>

Ex No: 07
Aim:
To create a Web site Using CSS.
Program :

<!DOCTYPE HTML>
<html>
<head>
<title>user registration form validation using javascript with example</title>
<style>
*{
margin:0px;
padding:0px;
}
body{
font-family:Tahoma, Geneva, sans-serif;
}
#container{
width:550px;
background-color:rgba(250,250,252,.9);
margin:auto;
margin-top:10px;
margin-bottom:10px;
box-shadow:0 0 3px #999;
}
#container_body{
padding:20px;
}
.form_title{
font-size:35px;
color:#141823;
text-align:center;
padding:10px;
font-weight:normal;
}
.head_para{
font-size:19px;
color:#99a2a7;
text-align:center;
font-weight:normal;
}
#form_name{
padding:25px 0 0 15px;
}
.firstnameorlastname{
margin-right:20px;

}
.input_name{
width:207px;
padding:5px;
font-size:18px;
}
#email_form{
clear:both;
padding:15px 0 10px 0px;
}
.input_email{
width:434px;
padding:5px;
font-size:18px;
}
#Re_email_form{
padding:10px 0 10px 0px;
}
.input_Re_email{
width:434px;
padding:5px;
font-size:18px;
}
#password_form{
padding:10px 0 10px 0px;
}
.input_password{
width:434px;
padding:5px;
font-size:18px;
}
.birthday_title{
font-size:16px;
color:#8b919d;
font-weight:normal;
padding:0 0 10px 0;
}
select{
padding:5px;
}
#birthday{
font-size:12px;
color:#8b919d;
padding-top:10px;
}
#radio_button{

padding:10px 0 0 0;
}
#sign_user{
font-size:14px;
color:#FFF;
text-align:center;
background-color:#3B5998;
padding:10px;
margin-top:10px;
cursor: pointer;
}
#errorBox{
color:#F00;
}

</style>
<script>
function Submit(){
var emailRegex = /^[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}$/;
var fname = document.form.Name.value,
lname = document.form.LastName.value,
femail = document.form.Email.value,
freemail = document.form.enterEmail.value,
fpassword = document.form.Password.value,
fmonth = document.form.birthday_month.value,
fday = document.form.birthday_day.value,
fyear = document.form.birthday_year.value;
if( fname == "" )
{
document.form.Name.focus() ;
document.getElementById("errorBox").innerHTML = "enter the first name";
return false;
}
if( lname == "" )
{
document.form.LastName.focus() ;
document.getElementById("errorBox").innerHTML = "enter the last name";
return false;
}
if (femail == "" )
{
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the email";

return false;
}else if(!emailRegex.test(femail)){
document.form.Email.focus();
document.getElementById("errorBox").innerHTML = "enter the valid email";
return false;
}
if (freemail == "" )
{
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "Re-enter the email";
return false;
}else if(!emailRegex.test(freemail)){
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "Re-enter the valid email";
return false;
}
if(freemail != femail){
document.form.enterEmail.focus();
document.getElementById("errorBox").innerHTML = "emails are not matching,
re-enter again";
return false;
}
if(fpassword == "")
{
document.form.Password.focus();
document.getElementById("errorBox").innerHTML = "enter the password";
return false;
}
if (fmonth == "") {
document.form.birthday_month.focus();
document.getElementById("errorBox").innerHTML = "select the birthday
month";
return false;
}
if (fday == "") {
document.form.birthday_day.focus();
document.getElementById("errorBox").innerHTML = "select the birthday day";
return false;
}
if (fyear == "") {
document.form.birthday_year.focus();
document.getElementById("errorBox").innerHTML = "select the birthday year";

return false;
}
if(document.form.radiobutton[0].checked == false &&
document.form.radiobutton[1].checked == false){
document.getElementById("errorBox").innerHTML = "select your
gender";
return false;
}
if(fname != '' && lname != '' && femail != '' && freemail != '' && fpassword != ''
&& fmonth != '' && fday != '' && fyear != ''){
document.getElementById("errorBox").innerHTML = "form submitted
successfully";
}
}
</script>
</head>
<body>
<div id="description"></div>
<!--container start-->
<div id="container">
<div id="container_body">
<div>
<h2 class="form_title">User Registration Form Demo</h2>
<p class="head_para">Form Validated Using Javascript</p>
</div>
<!--Form start-->
<div id="form_name">
<div class="firstnameorlastname">
<form name="form" >
<div id="errorBox"></div>
<input type="text" name="Name" value="" placeholder="First Name" class="input_name"
>
<input type="text" name="LastName" value="" placeholder="Last Name"
class="input_name" >
</div>
<div id="email_form">
<input type="text" name="Email" value="" placeholder="Your Email"
class="input_email">
</div>
<div id="Re_email_form">
<input type="text" name="enterEmail" value="" placeholder="Re-enter Email"
class="input_Re_email">

</div>
<div id="password_form">
<input type="password" name="Password" value="" placeholder="New Password"
class="input_password">
</div>
<!--birthday details start-->
<div>
<h3 class="birthday_title">Birthday</h3>
</div>
<div>
<select name="birthday_month" >
<option value="" selected >Month</option>
<option value="1">Jan</option>
<option value="2">Feb</option>
<option value="3">Mar</option>
<option value="4">Apr</option>
<option value="5">May</option>
<option value="6">Jun</option>
<option value="7">Jul</option>
<option value="8">Aug</option>
<option value="9">Sep</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
&nbsp;&nbsp;
<select name="birthday_day" >
<option value="" selected>Day</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>

<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
&nbsp;&nbsp;
<select name="birthday_year">
<option value="" selected>Year</option>
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
</select>
</div>
<!--birthday details ends-->
<div id="radio_button">
<input type="radio" name="radiobutton" value="Female">

<label >Female</label>
&nbsp;&nbsp;&nbsp;
<input type="radio" name="radiobutton" value="Male">
<label >Male</label>
</div>
<div>
<p id="sign_user" onClick="Submit()">Sign Up </p>
</div>
</form>
</div>
<!--form ends-->
</div>
</div>
<!--container ends-->
</body>
</html>
Output:

Ex No : 8
Aim :

To Create simple application to access data base using JDBC


Program :

import java.sql.*;
public class MsAcessODBC
{
public static void main(String[] args)
{
try
{
// loading thejdbc odbc driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// creating connection toth data base
Connection con = DriverManager.getConnection("jdbc:odbc:mydsn","","");
Statement st = con.createStatement();
// create an execute sql command on database
ResultSet rs = st.executeQuery("Select * from student order by rollno asc");
ResultSetMetaData rsmd = rs.getMetaData();
// this getColumnCount reurn the number of column in the selected table
int numberOfColumns = rsmd.getColumnCount();
// while loop and with while loop code use for print the data
while (rs.next())
{
for (int i = 1; i <= numberOfColumns; i++)
{
if (i > 1)
System.out.print(", ");
String columnValue = rs.getString(i);
System.out.print(columnValue);
}
System.out.println("");
}
st.close();
con.close();
} catch (Exception ex)
{
System.err.print("Exception: ");
System.err.println(ex.getMessage());
}
}
}
Ex No : 09
Aim :

To create a Program using PHP database functions.


Program :
Connect.php

<?php
//connect to the database
mysql_connect ("localhost","root","") or die ('Cannot connect to MySQL: ' . mysql_error());
mysql_select_db ("test") or die ('Cannot connect to the d
atabase: ' . mysql_error());
//query
$query = mysql_query("select name from sample") or die ('Query is invalid: ' . mysql_error());
//write the results
while ($row = mysql_fetch_array($query)) {
echo $row['name'] . " " . $row['name'] . "";
// close the loop
}
?>
Test.html
<html>
<head></head>
<body>
<?php
$host="localhost";
$user="root";
$password="";
$con=mysql_connect($host,$user,$password);
if($con)
{
mysql_select_db("test",$con)
or die(mysql_error());
$query=mysql_query("inset into sample values('1','sarath','70')");
echo '<h1>Values inserted</h1>';
}
else
{
echo '<h1>MySQL Server is not connected</h1>';
}
?>
</body>
</html>
Ex No : 10
Aim :
To Implement RMI concept for building any remote method of your choice.

Program :

public interface ShapeArea extends java.rmi.Remote


{
public long sqarea(int a) throws java.rmi.RemoteException;
public long recarea(int a,int b) throws java.rmi.RemoteException;
}
ShapeAreaClient.java
import java.rmi.Naming;
import java.io.*;
import java.rmi.RemoteException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
public class ShapeAreaClient {
public static void main(String[] args) {
try {
ShapeArea c = (ShapeArea) Naming.lookup("rmi://localhost/ShapeAreaService");
BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the shape option 1.square 2.Rectangle");
int a = Integer.parseInt(object.readLine());
switch(a)
{
case 1:
System.out.println("Enter the side of a square:");
int x=Integer.parseInt(object.readLine());
System.out.println( "The area is"+c.sqarea(x) );
break;
case 2:
System.out.println("Enter the Length & breadth of a Rectangle:");
int y=Integer.parseInt(object.readLine());
int z=Integer.parseInt(object.readLine());
System.out.println( "The area is"+c.recarea(y,z) );
break;
}
}
catch (Exception e) {
System.out.println("exception"+e);
}
}
}

ShapeAreaImpl.java
public class ShapeAreaImpl extends java.rmi.server.UnicastRemoteObject implements
ShapeArea
{
public ShapeAreaImpl() throws java.rmi.RemoteException
{
super();
}
public long sqarea(int a) throws java.rmi.RemoteException
{
int y= a*a;
return y;
}
public long recarea(int a,int b) throws java.rmi.RemoteException
{
int y= a*b;
return y;
}
}
ShapeAreaServer.java
import java.rmi.Naming;
public class ShapeAreaServer {
public ShapeAreaServer() {
try {
ShapeArea c = new ShapeAreaImpl();
Naming.rebind("rmi://localhost:1099/ShapeAreaService", c);
} catch (Exception e) {
System.out.println("exception"+e);
} }
public static void main(String args[]) {
new ShapeAreaServer();
}
}

Ex No : 11
Aim :
To Write a program to implement web service for calculator application

Program :
Calculator.java

package mypack;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;
/**
* This class was generated by the JAXWS SI.
* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebService(name = "Calculator", targetNamespace = "http://p1/")
public interface Calculator {
/**
*
* @param arg1
* @param arg0
* @return
* returns java.lang.String
*/
@WebMethod
@WebResult(targetNamespace = "")
@RequestWrapper(localName = "sum", targetNamespace = "http://p1/", className =
"mypack.Sum")
@ResponseWrapper(localName = "sumResponse", targetNamespace = "http://p1/",
className = "mypack.SumResponse")
public String sum(
@WebParam(name = "arg0", targetNamespace = "")
int arg0,
@WebParam(name = "arg1", targetNamespace = "")
int arg1);
}
CalculatorService.java
package mypack;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;
/**
* This class was generated by the JAXWS SI.

* JAX-WS RI 2.0_02-b08-fcs
* Generated source version: 2.0
*
*/
@WebServiceClient(name = "CalculatorService", targetNamespace = "http://p1/",
wsdlLocation = "http://localhost:8081/MyCalculatorWs/CalculatorService?WSDL")
public class CalculatorService
extends Service
{
private final static URL CALCULATORSERVICE_WSDL_LOCATION;
static {
URL url = null;
try {
url = new URL("http://localhost:8081/MyCalculatorWs/CalculatorService?
WSDL");
} catch (MalformedURLException e) {
e.printStackTrace();
}
CALCULATORSERVICE_WSDL_LOCATION = url;
}
public CalculatorService(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public CalculatorService() {
super(CALCULATORSERVICE_WSDL_LOCATION, new QName("http://p1/",
"CalculatorService"));
}
/**
*
* @return
* returns Calculator
*/
@WebEndpoint(name = "CalculatorPort")
public Calculator getCalculatorPort() {
return (Calculator)super.getPort(new QName("http://p1/", "CalculatorPort"),
Calculator.class);
}
}
ObjectFactory.java
package mypack;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;

import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the mypack package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _Sum_QNAME = new QName("http://p1/", "sum");
private final static QName _SumResponse_QNAME = new QName("http://p1/",
"sumResponse");
/**
* Create a new ObjectFactory that can be used to create new instances of schema
derived classes for package: mypack
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link Sum }
*
*/
public Sum createSum() {
return new Sum();
}
/**
* Create an instance of {@link SumResponse }
*
*/
public SumResponse createSumResponse() {
return new SumResponse();
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Sum }{@code >}}

*
*/
@XmlElementDecl(namespace = "http://p1/", name = "sum")
public JAXBElement<Sum> createSum(Sum value) {
return new JAXBElement<Sum>(_Sum_QNAME, Sum.class, null, value);
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link SumResponse }
{@code >}}
*
*/
@XmlElementDecl(namespace = "http://p1/", name = "sumResponse")
public JAXBElement<SumResponse> createSumResponse(SumResponse value) {
return new JAXBElement<SumResponse>(_SumResponse_QNAME,
SumResponse.class, null, value);
}
}
package-info.java:
@javax.xml.bind.annotation.XmlSchema(namespace = "http://p1/")
package mypack;
Sum.java
package mypack;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for sum complex type.
*
* <p>The following schema fragment specifies the expected content contained within
this class.
*
* <pre>
* &lt;complexType name="sum">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
*
&lt;sequence>
*
&lt;element name="arg0" type="{http://www.w3.org/2001/XMLSchema}int"/>
*
&lt;element name="arg1" type="{http://www.w3.org/2001/XMLSchema}int"/>
*
&lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>

* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sum", propOrder = {
"arg0",
"arg1"
})
public class Sum {
protected int arg0;
protected int arg1;
/**
* Gets the value of the arg0 property.
*
*/
public int getArg0() {
return arg0;
}
/**
* Sets the value of the arg0 property.
*
*/
public void setArg0(int value) {
this.arg0 = value;
}
/**
* Gets the value of the arg1 property.
*
*/
public int getArg1() {
return arg1;
}
/**
* Sets the value of the arg1 property.
*
*/
public void setArg1(int value) {
this.arg1 = value;
}
}
SumResponse.java

package mypack;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
* <p>Java class for sumResponse complex type.
*
* <p>The following schema fragment specifies the expected content contained within
this class.
*
* <pre>
* &lt;complexType name="sumResponse">
* &lt;complexContent>
* &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
*
&lt;sequence>
*
&lt;element name="return"
type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
*
&lt;/sequence>
* &lt;/restriction>
* &lt;/complexContent>
* &lt;/complexType>
* </pre>
*
*
*/
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "sumResponse", propOrder = {
"_return"
})
public class SumResponse {
@XmlElement(name = "return")
protected String _return;
/**
* Gets the value of the return property.
*
* @return
* possible object is
* {@link String }
*
*/
public String getReturn() {

return _return;
}
/**
* Sets the value of the return property.
*
* @param value
* allowed object is
* {@link String }
*
*/
public void setReturn(String value) {
this._return = value;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>CalculatorEx</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.restful.demo.resources</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping></web-app>
Ex No : 12

Aim :
To write a Program for Reading and Writing the files using .Net.
Program :
Read.css:
//Read a Text File
using System;
using System.IO;
namespace readwriteapp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
String line;
try
{
//Pass the file path and file name to the StreamReader constructor
StreamReader sr = new StreamReader("C:\\Sample.txt");
//Read the first line of text
line = sr.ReadLine();
//Continue to read until you reach end of file
while (line != null)
{
//write the lie to console window
Console.WriteLine(line);
//Read the next line
line = sr.ReadLine();
}
//close the file
sr.Close();
Console.ReadLine();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}}
Write.css:

using System;
using System.IO;
namespace readwriteapp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
try
{
//Pass the filepath and filename to the StreamWriter Constructor
StreamWriter sw = new StreamWriter("C:\\Test.txt");
//Write a line of text
sw.WriteLine("Hello World!!");
//Write a second line of text
sw.WriteLine("From the StreamWriter class");
//Close the file
sw.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e.Message);
}
finally
{
Console.WriteLine("Executing finally block.");
}
}
}
}

Das könnte Ihnen auch gefallen