web technology laboratory manual

Embed Size (px)

Citation preview

  • 8/2/2019 web technology laboratory manual

    1/64

    Ex No: 1

    Date: WEBSITE CREATION FOR FACULTY DEVELOPMENT PROGRAM

    Aim:

    To develop a website for faculty development program using DHTML and CSS.

    Procedure:

    1. Create the main.html with three frames using the tag as follows

    2. Create the home.html that is on the right side of first.html with the CSS style asfollows

    body

    {

    background-image: url("img149.jpg");

    background-repeat: repeat

    }

    h1 {background-color: pink}

    h2 {background-color: transparent}

    p {background-color: rgb(25,20,25)}

    The stylesheet is stored in a seperate file which can be linked to any number of htmldocuments using the follwing tag.

    3. The home.html is having the files of home.html, course.html, syllabus.html,schedule.html, fees.html, regulations.html and contacts.html each gives the details about the

    appropriate FDP regarding details.

    4. The syllabus link of the details.html has created as rich text format using the tag

    Syllabus

    5. In home.html the body background image has set using

    1

  • 8/2/2019 web technology laboratory manual

    2/64

    6. Hyperlinks can be given using

    Click here to view the website of AnnaUniversity of

    Technology , Tiruchirapalli

    7. In fees.html the table has created using the tag

    Fees Details :--

    Serial

    Details

    Fees

    9.The word FACULTY DEVELOPMENT PROGRAM has scrolled horizontally using

    FACULTY DEVELOPMENT PROGRAM

    2

  • 8/2/2019 web technology laboratory manual

    3/64

    Program:

    main.html









    smain.css

    body{

    background-color:skycolor;}h1{class="veryimportant";

    font-size: 20pt;color: red;}

    p{font-size: 16pt; word-spacing:1 em;text-indent: 0.5in;}a:link{color:blue;}a:visited{color:red;}

    right.html

    Anna University is offering several courses for the students as well as for the facultymembers.

    3

  • 8/2/2019 web technology laboratory manual

    4/64

    left.html









    head.html

    home.html

    M.E(CSE) - MBCBS Home Page

    About College

    Anna University, Trichy has been started during the year of 2007 at Bharathidasan Univeristycampus

    Vision

    To actively support an academic environment as a Central ComprehensiveLearning Centre that commits for the intellectual development of all learners through courses,Training Programmes and discipline specific assistance that helps them succeed in their careersand life.

    Mission

    4

  • 8/2/2019 web technology laboratory manual

    5/64

    To support an enhanced educational experience to academically talented and highlymotivated students

    To design, in collaboration with faculty recognized for excellence in teaching, an

    innovative, inter disciplinary and multidisciplinary curriculum that emphasizes critical thinking,collaborative learning and communication skills

    To supplement curriculum with enriched academic opportunities consisting of StudySmarter Programmes (SSP) , Campus Placement Training Programmes (CPTP), Soft SkillsDevelopment Programme (SSDP), Short Term Training Programmes (STTP) , FacultyDevelopment Programmes (FDP) , Learn by Doing Practices (LDP), and SupplementalInstruction (SI) to help the students to improve the

    course.html

    M.E(CSE)-MBCBS Course Structure

    p:first-letter{color: #ff000f;

    font-size:xx-large}

    About Course Structure

    This new course has been exclusively started for the faculty members who can get moreknowledge and can easily conveyed to their students

    Courses OfferedM.E.Computer Science Engineering

    M.E.Embedded Systems

    M.E.Applied Electronics

    M.E.Communication Engineering

    M.E.PowerSystems

    5

  • 8/2/2019 web technology laboratory manual

    6/64

    M.E.Structural Engineering

    M.E.Thermal Engineering

    M.E(CSE) Fee Detailsbody{color:Black;}

    Fee Details At The Time of AdmissionSl.NoDetailsAmount

    1Registration Fees6002Caution Deposit(Refundable)9,500

    3Provisional Certificate & Degree Certificate5004Cost of Regulation and Syllabus Book6005Examination Fees

    2,000

    6

  • 8/2/2019 web technology laboratory manual

    7/64

    6Library and Internet Charges5007

    Tuition Fees18,0008Total31,700

    Fee Details - Payable Every Semester

    Sl.NoDetailsAmount1Faculty Development Programme Fee2,500

    2Course Fee (per Credit)1,5003Examination Fee(per Subject)500

    Note: Semester fee varies according to the number of credits offered in that semester.

    7

  • 8/2/2019 web technology laboratory manual

    8/64

    syllabus.html

    DEPARTMENTM.E.Computer Science Engineering

    M.E.Embedded Systems

    M.E.Applied Electronics

    M.E.Communication Engineering

    M.E.PowerSystems

    M.E.Structural Engineering

    M.E.Thermal Engineering

    exam.html

    Exam Schedule

    Tentative Examination ScheduleSl.NoDateSubject Name

    105/06/2011Operating Systems Design207/06/2011Database Technology

    3

    8

  • 8/2/2019 web technology laboratory manual

    9/64

    09/06/2011Fundamentals of Pervasive Computing

    411/06/2011Web Technology Laboratory



    contact.html

    Address for Correspondence

    Address for Correspondence The Director(Admissions) Centre for Academic Excellence

    Anna University of Technology ( BIT Campus) Tiruchirapalli 620 024 0431-2407947

    Email : [email protected] Web : www.tau.edu.in

    9

  • 8/2/2019 web technology laboratory manual

    10/64

    Output:

    Home.html

    Course.html

    10

  • 8/2/2019 web technology laboratory manual

    11/64

    Fees.html

    syllabus.html

    11

  • 8/2/2019 web technology laboratory manual

    12/64

    exam.html

    Regulation output Screen

    12

  • 8/2/2019 web technology laboratory manual

    13/64

    Schedule Output Screen

    Contact.html

    Result:

    Thus the web site for FDP has been successfully created and verified.

    13

  • 8/2/2019 web technology laboratory manual

    14/64

    Ex No: 2

    Date: EMBED THE MULTIMEDIA OBEJECTS

    Aim:To develop a web page with multimedia objects of image, audio and video using java

    script with DHTML.

    Procedure:

    EMBEDDING IMAGES

    1. Create the image.html with CSS for setting the images at the correct index position

    #img1{position:absolute;left:"260px";top:"230px"}

    #img2{position:absolute;left:"290px";top:"260px"}

    #img3{position:absolute;left:"320px";top:"290px"}

    2. Using java script the image has been selected with their appropriate index position

    function image1()

    {

    img1.sytle.zIndex=3;

    img2.sytle.zIndix=2;

    img3.sytle.zIndex=1;

    }

    3. The three images are loaded into the web page with the tag

    The images can also be inserted using the following tag

    EMBEDDING AUDIO

    14

  • 8/2/2019 web technology laboratory manual

    15/64

    4. The audio is loaded in the audio.html using the tag

    5. The script to load an audio file is written at the head part of audo.html as follows

    if(MPlyr.IsSoundCardEnabled()==true)

    { MPlr.Play() }

    else

    {

    aler("No sound capability available. click ok to continue")

    }

    EMBEDDING VIDEO

    6. The video is loaded in the video.html using

    7. The video file properties like start, pause and stop are set using

    8. The video player properties like showDisplay and hideDisplay are set using

    Program:

    15

  • 8/2/2019 web technology laboratory manual

    16/64

    Anna University of Technology
    Tiruchirapalli - 620 024



  • 8/2/2019 web technology laboratory manual

    17/64

    ms_positioning="FlowLayout" language="javascript" onclick="returnDIV1_onclick()">

    Enter the File Name

    Enter The Typempegmp3JPEG/GIFFlash

    Output:

    17

  • 8/2/2019 web technology laboratory manual

    18/64

    Result:

    Thus the web page with multimedia objects has been created and verified successfully.

    Ex No: 3 XML DOCUMENT FOR THESTUDENTS OF AUT- T

    Date: WITH DTD/SCHEMA

    18

  • 8/2/2019 web technology laboratory manual

    19/64

    Aim:

    To develop an XML Document for the students of Anna University of Technology

    Tiruchirapalli and validate the same using DTD/SCHEMA.

    DTD

    The purpose of a DTD is to define the legal building blocks of an XML document. It

    defines the document structure with a list of legal elements. A DTD can be declared inline in

    the XML document, or as an external reference. DTD is a set of rules that defines what tag

    appear in a XML document, so that viewers of an XML document know what all the tags mean.

    The building blocks of XML documents XML documents (and HTML documents) are

    made up by the following building blocks :

    Elements, Tags, Attributes, Entities, PCDATA, and CDATA

    Elements Elements are the main building blocks of both XML and HTML documents.

    Tags Tags are used to markup elements.

    Attributes Attributes provide extra information about elements.

    PCDATA PCDATA means parsed character data

    CDATA CDATA also means character data. CDATA is text that will NOT be parsed by aparser

    Entities Entities as variables used to define common text. Entity references are references toentities.

    eg:

    SCHEMA

    XML Schema is an XML-based alternative to DTD. An XML schema describes the structure of

    an XML document. The XML Schema language is also referred to as XML Schema Definition

    19

  • 8/2/2019 web technology laboratory manual

    20/64

    (XSD).XML Schema became a W3C Recommendation 02. May 2001. The element

    is the root element of every XML Schema.

    The following fragment:

    xmlns:xs="http://www.w3.org/2001/XMLSchema"

    indicates that the elements and data types used in the schema come from the

    "http://www.w3.org/2001/XMLSchema" namespace. It also specifies that the elements and data

    types that come from the "http://www.w3.org/2001/XMLSchema" namespace should be

    prefixed with xs:

    Procedure:

    1. Design a General structure of the Student i.e., the structure of the Student Element.

    STUDENT (batchno,name,regno,branch,gender,address,sports,qualification);

    2. Create a DTD file which should check the XML document and tell whether the XML

    document has followed the syntax given in the DTD or not.

    3. If not suitable changes should be made in the XML document i.e., the application can

    use a standard DTD to verify that the data received from the outside world is valid or

    not.

    4. The DTD File is embedded in the XML file using the following code

    External DTD:

    where student.dtd is the name of the DTD file. The tags developed in the DTD can be

    used here for inserting the fields.

    Program:

    3 a) XML Document for the Students Details and DTD with DSS

    Student.cssstudent

    20

  • 8/2/2019 web technology laboratory manual

    21/64

    {background.color:#FFFABC;width=100%;}record

    {display:block;color:BLACK;font.size:20pt;}sno{display:block;color:GREEN;font.size:15pt;}

    sname{display:block;color:BLUE;font.size:15pt;}dob{display:block;color:VIOLET;font.size:15pt;

    }address{display:block;color:RED;font.size:15pt;}m1{display:block;

    color:INDIGO;font.size:15pt;}m2{ display:block;color:ROSE;font.size:15pt;}m3{display:block;

    color:RED;font.size:15pt;

    21

  • 8/2/2019 web technology laboratory manual

    22/64

    }

    student.dtd

    student.xml

    ?xml version="1.0"?>

    RECORD 101110901001ARUN BALAJI

    04/01/1983Trichy808590

    RECORD 201110901002

    ARUNABARATH04/02/1982Chennai908095Output:

    22

  • 8/2/2019 web technology laboratory manual

    23/64

    3 b) XML Document for the Students Details of AUT- T using XML with XSL

    student.xsl

    Anna University of TechnologyTiruchirapalli

    M.E (Modular Based Credit Banking System)Student Details

    Register Number

    NameDepartment

    Contact AddressContact Number

    23

  • 8/2/2019 web technology laboratory manual

    24/64

    student.xml

    01110901001GEETHACSE41/A KAMARAJAR

    STREET,TIRUCHY9995487548

    01110901002KARTHIKIT5,SOUTH STREET,TIRUCHY9854227548

    01110901003MALAIT12,WEST STREET,TIRUCHY9847852369

    01110901004MEENAKSHIIT

    6,KK NAGAR,TIRUCHY9258963549

    Output:

    24

  • 8/2/2019 web technology laboratory manual

    25/64

    Result:

    Thus the XML Document for the students of Anna University of Technology,

    Tiruchirapalli has been created and validated using DTD/SCHEMA

    Ex No: 4Date: A XML PARSER TO RETRIEVE STUDENT DETAILS USING DOM

    25

  • 8/2/2019 web technology laboratory manual

    26/64

    Aim:To develop an XML Parser using DOM to retrieve student details.

    XML DOM

    The XML DOM defines a standard for accessing and manipulating XML. The w3c

    document object model is a platform neutral interfcae that allows progrmas and scripts to

    dynamically access abd update the content, structure and style of a document. The XML DOM

    views an XML document as a tree-structure. The tree structure is called a node-tree. All nodes

    can be accessed through the tree. Their contents can be modified or deleted, and new elements

    can be created. The terms parent, child, and sibling are used to describe the relationships. Parent

    nodes have children. Children on the same level are called siblings (brothers or sisters).

    In a node tree, the top node is called the root

    1 Every node, except the root, has exactly one parent node

    2 A node can have any number of children

    3 A leaf is a node with no children

    4 Siblings are nodes with the same parent

    Because the XML data is structured in a tree form, it can be traversed without knowing the

    exact structure of the tree and without knowing the type of data contained within.

    Procedure:

    i. Create an XML Document, which contains the details of the students.

    26

  • 8/2/2019 web technology laboratory manual

    27/64

    ii. Embed the and

    tags top of the HTML document.

    iii. Create a HTML page with suitable tags, which will display the headings of the given

    student.

    iv. A suitable logic is developed by using and to display the contents from the XML document to the HTMLdocument.

    Program:

    studentbio.xml

    ANAND S. SIVARAMAN K. 02/05/1987 1, FIRST MAIN ROAD, TOLGATE,

    TIRUCHIRAPPALLI

    [email protected] 9976564523 CSE

    GOWRI A. ANBU M. 12/11/1985 12, PONNAPAR STREET, DINDIGUL

    [email protected] 9997099009 ES

    SUBRAMANIYAN D. BALAN M. 02/05/1987 12, TVK STREET, ARIALUR

    [email protected] 9787563412

    27

    http://www.w3.org/TR/WD-xsl%3E%20%20and%20%3Cxsl:template%20match=http://www.w3.org/TR/WD-xsl%3E%20%20and%20%3Cxsl:template%20match=http://www.w3.org/TR/WD-xsl%3E%20%20and%20%3Cxsl:template%20match=http://www.w3.org/TR/WD-xsl%3E%20%20and%20%3Cxsl:template%20match=http://www.w3.org/TR/WD-xsl%3E%20%20and%20%3Cxsl:template%20match=
  • 8/2/2019 web technology laboratory manual

    28/64

    PS

    biodata.xsl

    ANNA UNIVERSITY OF TECHNOLOGY, TIRUCHIRAPPALLI STUDENT BIODATA

    COURSE: M.E. THROUGH MBCBS

    NAME FATHER'S NAME DATE OF BIRTH ADDRESS PHONE DEPARTMENT

    Output:

    28

  • 8/2/2019 web technology laboratory manual

    29/64

    Result:

    Thus an XML parser is developed using DOM to retrieve the student information.

    Ex No: 5Date: A PHP PROGRAM TO DISPLAY THE DETAILS OF FACULTY

    29

  • 8/2/2019 web technology laboratory manual

    30/64

    Aim:

    To write PHP program to display the details of Faculty with their expertise.

    Procedure:

    i. Create a database in MySQL RDBMS which contains the details of the Faculty.

    ii. Give the code $database=mysql_connect("localhost","root","") to connect to the

    MySql DB.

    iii. Build query using SELECT SQL statement.iv. Execute the query.

    v. Display all records in the table using the loop statement along with display formats.

    Program:

    Facultydata.php

    FACULTY NAME LIST

    NAMES OF THE FACULTY WITH THIER EXPERTISE

    NAME PHONE

    E-MAIL ID EXPERTISE

    30

  • 8/2/2019 web technology laboratory manual

    31/64

    Output:

    31

  • 8/2/2019 web technology laboratory manual

    32/64

    Result

    Thus the PHP program to display the details of Faculty with their expertise was developed.Ex No: 6

    Date: A CHAT APPLICATION USING SOCKETS

    32

  • 8/2/2019 web technology laboratory manual

    33/64

    Aim:

    To write a Java program to implement a Chat application using sockets.

    Procedure:

    Server side

    1. Import the necessary header files.

    import java.net.*;

    2. Bind the server with the specified port using ServerSocket.

    ServerSocket ss=new ServerSocket(5000);

    3. Listening for the clients to connect to the server.

    Socket soc=ss.accept();

    4. Repeatedly chat with the client using the following format. Out the data to be sent to

    the client. And In the data send by the client.

    DataInputStream dis=new DataInputStream(System.in);

    DataInputStream sdis=new DataInputStream(soc.getInputStream());

    PrintStream ps=new PrintStream(soc.getOutputStream());

    String s1=dis.readLine();

    ps.println(s1);

    5. Close the socketsSoc.close();

    Client Side

    1. Import the necessary header files.

    import java.net.*;

    2. Connect the client with the specified port using Socket.

    Socket s=new Socket(cse21,5000);

    3. Repeatedly chat with the server using the following format. Out the data to be sent to

    the server. And In the data send by the server.

    DataInputStream dis=new DataInputStream(System.in);

    DataInputStream sdis=new DataInputStream(soc.getInputStream());

    33

  • 8/2/2019 web technology laboratory manual

    34/64

    PrintStream ps=new PrintStream(soc.getOutputStream());

    String s1=dis.readLine();

    ps.println(s1);

    4. Close the sockets

    Soc.close();

    Program:

    //server.java

    import java.net.*;import java.io.*;

    34

  • 8/2/2019 web technology laboratory manual

    35/64

    public class server

    {

    public static void main(String[ ] args) throws Exception

    {

    ServerSocket ss=new ServerSocket(5000);

    Socket soc=ss.accept();

    DataInputStream dis=new DataInputStream(System.in);

    DataInputStream sdis=new DataInputStream(soc.getInputStream());

    PrintStream ps=new PrintStream(soc.getOutputStream());

    while(true)

    {

    String s1=sdis.readLine();

    System.out.print("\nClient:"+s1);

    if(s1.equals("end"))

    {

    soc.close();

    break;

    }

    else

    {

    System.out.print("\nServer:");

    String s2=dis.readLine();

    ps.println(s2);

    if(s2.equals("end"))

    {

    soc.close();

    break;

    }

    }

    } } }

    //Client.java

    import java.net.*;

    import java.io.*;

    35

  • 8/2/2019 web technology laboratory manual

    36/64

    public class client

    { public static void main(String [] args) throws Exception

    {

    Socket soc=new Socket("localhost",5000);

    DataInputStream dis=new DataInputStream(System.in);

    DataInputStream sdis=new DataInputStream(soc.getInputStream());

    PrintStream ps=new PrintStream(soc.getOutputStream());

    while(true)

    {

    System.out.print("\nClient:");

    String s1=dis.readLine();

    ps.println(s1);

    if(s1.equals("end"))

    {

    soc.close();

    break;

    }

    else

    {

    String s2=sdis.readLine();

    System.out.print("\nServer:"+s2);

    if(s2.equals("end"))

    {

    soc.close();

    break;

    }

    }

    }

    }

    }

    Output:

    36

  • 8/2/2019 web technology laboratory manual

    37/64

    Result:

    Thus the program for chat application using sockets has been completed and verified.

    37

  • 8/2/2019 web technology laboratory manual

    38/64

    Ex No: 7

    Date: AN I/O STREAMING MODEL

    Aim:

    To write a Java program to illustrate I/O streaming using FTP.

    Procedure:

    Java performs I/O through streams. A Stream is an abstraction that either produces or

    consumes information.

    Reading Console Input

    1. Import the necessary header files.

    import java.io.*;

    2. Reading Console Input

    The console input is accomplished by reading through System.in. To obtain a

    character based stream that is attached to the console, wrap System.in a

    BufferedReader object.

    InputStream is = soc.getInputStream();

    InputStreamReader isr = new InputStreamReader(is);

    BufferedReader br = new BufferedReader(isr);

    3. Writing Console Output

    PrintStream is an output stream derived from OutputStream, it also implements the

    low level method write()

    Void write(int byteval);

    4. Reading and Writing Files

    In java, all files are byte-oriented and java provides methods to read and write bytes from

    and to a file.File f = new File("a.txt");

    FileInputStream fis = new FileInputStream(f);

    OutputStream os = soc.getOutputStream();

    PrintStream ps = new PrintStream(os);

    String data;

    while((data=br.readLine())!=null)

    ps.println(data);

    5. Close all the File Input and Outstreams.

    38

  • 8/2/2019 web technology laboratory manual

    39/64

    Program:

    //ftpserver.java

    import java.io.*;import java.net.*;

    public class FTPServer{public static void main(String []args)throws Exception{

    System.out.println("FTP Server started...");ServerSocket ss = new ServerSocket(5000);Socket soc = ss.accept();

    File f = new File("a.txt");FileInputStream fis = new FileInputStream(f);InputStreamReader isr = new InputStreamReader(fis);

    BufferedReader br = new BufferedReader(isr);

    OutputStream os = soc.getOutputStream();PrintStream ps = new PrintStream(os);

    String data;

    while((data=br.readLine())!=null)ps.println(data);

    System.out.println("File Transfer Completed...");

    br.close();ps.close();soc.close();

    } }

    //ftpclient.java

    import java.io.*;

    import java.net.*;

    public class FTPClient{

    public static void main(String []args)throws Exception{

    Socket soc = new Socket("localhost",5000);

    File f = new File("b.txt");FileOutputStream fos = new FileOutputStream(f);

    PrintStream ps = new PrintStream(fos);

    39

  • 8/2/2019 web technology laboratory manual

    40/64

    InputStream is = soc.getInputStream();InputStreamReader isr = new InputStreamReader(is);BufferedReader br = new BufferedReader(isr);

    String data;

    int i=1;while((data = br.readLine())!=null){

    ps.println(data);System.out.println(data);

    }

    System.out.println("File Transfer Completed...");br.close();ps.close();soc.close();

    }

    }

    //charsetream.java

    import java.io.*;class charstream{

    public static void main(String args[]) throws IOException{BufferedReader br1=new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter the file name:");String fname=br1.readLine();FileWriter fo=new FileWriter(fname);BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));String s;System.out.println("enter the line of text here");System.out.flush();

    s=br2.readLine();for(int i=0;i

  • 8/2/2019 web technology laboratory manual

    41/64

    Output:

    Result:

    Thus the program for illustrating Streams has been completed and verified.

    Ex No: 8

    Date: AN IMPLEMENTATION OF PING COMMAND

    Aim:

    To develop a program in java for implementing ping command.

    Procedure:

    Ping is a computer network tool used to test whether a particular host is reachable across anIP network; it is also used to self-test the network interface cord of the computer. It works bysending ICMP echo request packets to the target host and listening for ICMP echo response

    replies. Ping estimates the round-trip time, generally in milliseconds, and records any packetloss, and prints a statistical summary when finished.

    41

  • 8/2/2019 web technology laboratory manual

    42/64

    1. Import the necessary java files.

    2. Using command line argument the remote machine IP address is assigned to the variableip as follows.

    String ip = args[0];

    3. Using the following statements the ping command of the remote machine is initiated atthe current running machine.

    String pingCmd = "ping " + ip;

    Runtime r = Runtime.getRuntime();

    Process p = r.exec(pingCmd);

    4. The status of remote machine has been displayed at the current machine using thefollowing statements.

    BufferedReader in = new BufferedReader(new

    InputStreamReader(p.getInputStream()));

    String inputLine;

    while ((inputLine = in.readLine()) != null) {

    System.out.println(inputLine);

    5. If there is a connection with the system, it sends the number of bytes received or else itdisplays "Request timed out"

    Program:

    import java.net.*;

    import java.io.*;import java.util.*;

    public class Ping {

    public static void main(String[] args) {

    String ip = args[0];String pingResult = "";

    String pingCmd = "ping " + ip;

    try {

    42

  • 8/2/2019 web technology laboratory manual

    43/64

    Runtime r = Runtime.getRuntime();Process p = r.exec(pingCmd);

    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));String inputLine;

    while ((inputLine = in.readLine()) != null) {System.out.println(inputLine);//pingResult += inputLine;}in.close();

    }//trycatch (IOException e) {System.out.println(e);}

    }

    }

    Output:

    43

  • 8/2/2019 web technology laboratory manual

    44/64

    Result:

    Thus the ping command has been successfully implemented and verified.

    Ex No: 9

    Date: A SIMULATION OF SMTP

    Aim:

    To develop a program in Java to simulate SMTP.

    SMTP

    The Simple Mail transfer Protocol is used to create mail like a postal mail. It has both

    the sender and the receiver address. At the Sender side, The message header consists of sender

    address, receiver address and subject field. And the body field contains the actual information to

    be sent. In the receiver side, The email system periodically checks the mailboxes. If a user has

    mail, it informs the user with a notice. If the user is ready to read the mail, a list is displayed in

    which each line contains a summary of the information about a particular message in the

    mailbox. Summary contains the sender mail address, the subject, and time the mail was sent or

    received. SMTP is a push protocol; it pushes the message from the sender to the receiver even if

    the receiver does not want it.

    Procedure:

    1. An SMTP server has been designed to send an email to the concerned recipient using theSMTP mail format

    44

  • 8/2/2019 web technology laboratory manual

    45/64

    2. The email system needs information likea. SMTP Server Name

    b. Sender Email IDc. Receiver Email Id

    3. A Socket connection has been created in the following formatSocket s = new Socket(smtpserver, 25);

    4. The email has been sent to recipient using the format of

    HELO recipient

    250 Ok (from recipient)

    MAIL FROM: [email protected]

    250 [email protected] Ok

    RCPT TO: [email protected]

    250 Ok

    DATAWelcome

    . (period to stop the transfer)

    5. Using the socket connection the data has been sent to the recipient machine.

    Program:

    import java.awt.*;import java.awt.event.*;//import java.util.*;import java.net.*;import java.io.*;import java.applet.*;//

    public class SMTP extends Applet implements ActionListener{

    private BufferedReader in;private PrintWriter out;private TextField from, to , server;

    private TextArea message, response;private Button send;

    45

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 8/2/2019 web technology laboratory manual

    46/64

    public void init(){setLayout(new GridBagLayout());GridBagConstraints gbc = new GridBagConstraints();

    gbc.fill = GridBagConstraints.NONE;gbc.anchor = GridBagConstraints.NORTHWEST;gbc.weightx = 1;gbc.weighty = 0;

    addUsingGBL(new Label(" SMTP SERVER: "), gbc, 0, 0, 1, 1);addUsingGBL(new Label(" FROM: "), gbc, 0, 1, 1, 1);addUsingGBL(new Label(" TO: "), gbc, 0, 2, 1, 1);

    server = new TextField("localhost");

    from = new TextField("[email protected]");to = new TextField("[email protected]");addUsingGBL(server, gbc, 1, 0, 2, 1);addUsingGBL(from, gbc, 1, 1, 2, 1);addUsingGBL(to, gbc, 1, 2, 2, 1);addUsingGBL(new Label(""), gbc, 0, 3, 1, 1);send = new Button("SEND EMAIL");addUsingGBL(send, gbc, 1, 4, 1, 1);send.addActionListener(this);

    addUsingGBL(new Label(""), gbc, 0, 5, 1, 1);

    message = new TextArea("");response = new TextArea("");addUsingGBL(message, gbc, 0, 6, 3, 1);addUsingGBL(response, gbc, 0, 7, 3, 1);}

    void addUsingGBL(Component component, GridBagConstraints gbc, int x, int y, int w, inth){

    gbc.gridx = x;gbc.gridy = y;gbc.gridwidth = w;gbc.gridheight = h;add(component, gbc);}

    public void actionPerformed(ActionEvent evt){String str = evt.getActionCommand();

    if (str.equals("SEND EMAIL")){

    46

  • 8/2/2019 web technology laboratory manual

    47/64

    sendMail();}}

    public void sendMail(){

    try{Socket s = new Socket(server.getText(), 25);

    out = new PrintWriter(s.getOutputStream());in = new BufferedReader(new InputStreamReader(s.getInputStream()));

    String hostName = InetAddress.getLocalHost().getHostName();

    send(null);send("HELO " + hostName);

    send("MAIL FROM: " + from.getText());send("RCPT TO: " + to.getText());send("DATA");out.println(message.getText());send(".");s.close();}catch (IOException exception){response.append("Error: " + exception);}

    }public void send(String s) throws IOException{if (s != null){response.append(s + "\n");out.println(s);out.flush();}String line;

    if ((line = in.readLine()) != null)response.append(line + "\n");}

    public static void main(String[] args){SMTP a = new SMTP();a.init();a.start();Frame f= new Frame("SEND MAIL");f.addWindowListener(new java.awt.event.WindowAdapter(){

    public void windowClosing(java.awt.event.WindowEvent e){

    47

  • 8/2/2019 web technology laboratory manual

    48/64

    System.exit(0);};});f.add("Center", a);f.pack();f.setSize(360,500);

    f.setLocation(100,100);f.show();}}

    Output:

    48

  • 8/2/2019 web technology laboratory manual

    49/64

    Result:

    Thus SMTP mail service is simulated with the appropriate format.

    Ex No: 10

    Date: A SIMULATION OF HTTP

    49

  • 8/2/2019 web technology laboratory manual

    50/64

    Aim:

    To implement the http protocol in java.

    Procedure:

    In this program, a browser has been developed as an HTTP client and a web server as anHTTP server. An HTTP client sends a request to the server followed by request headers and a

    blank line. It then reads the status line, response headers, and the requested file from the server.An HTTP server reads the request from the client, header details and in some cases additionaldata. It sends a status line followed by headers and the requested resource, if any.

    Browser.java

    1. Import all the necessary files.

    2. The user is allowed to pass the server port number on which it will run as thewebserver program and the connection with the webserver has been establishedusing the following statements in the browser.

    int port = Integer.parseInt(args[1]);

    Socket server = new Socket(args[0],port);

    System.out.println("Connected to host" + server.getInetAddress());

    3. The path to the resource, (/~artg/TryURL.java) is set by sending the host address and

    port in a separate Host header as follows.

    PrintWriter toServer = new PrintWriter(server.getOutputStream(),true);

    toServer.println("GET"+args[2]+"HTTP/1.0");

    toServer.println("Host:"+args[0]+':'+args[1]);

    toServer.println();

    4. The status line and headers sent by the server & looking for the blank line thatsignals the end of the headers and the start of the file we requested has been initiated

    by the following statements.

    while(!(s=fromServer.readLine()).equals(""));

    5. The following loop reads the file we requested from the server, displaying it in thecommand window.

    while((s=fromServer.readLine())!= null)

    System.out.println(s);

    WebServer.java

    1. Import the necessary files.

    50

  • 8/2/2019 web technology laboratory manual

    51/64

    2. Read the first line from the client to find the method and the identifier for theresource.

    s = fromClient.readLine();

    3. Using StringTokenizer, the method and parts of the request has been identified

    StringTokenizer tokens = new StringTokenizer(s);

    4. If the request method is anything other than GET, the server sends a status line witha code of 501 to indicate that the method can not implemented.

    if(!(tokens.nextToken()).equals("GET")){

    toClient.println("HTTP/1.0 501 Not implemented");

    toClient.println();

    5. The file name after GET is separated by a blank in the request of the client. It hasbeen saved before reading the next line from the client, which will overwrite thestring s as follows.

    String filename = tokens.nextToken();

    6. By the following statements, we can read and ignore any request headers sent by theclient, looking for the blank line that separates the request and hreaders form anydata the client might send.

    while(!(s = fromClient.readLine()).equals(""));

    7. If file cannot be found or another error occurs, the exception thrown will causecontrol to jump to the catch clause and the server to terminate by the followingstatements.

    BufferedReader file = new BufferedReader(new FileReader(filename));8. Having created the file to send, the server sends a status line with code 200 meaning

    OK. And follows with one header describing the content type to help the client to

    display it.

    toClient.println("HTTP/1.0 200 OK");

    toClient.println("content type: text/plain");

    9. The following loop sends the file to the client.

    while((s=file.readLine())!=null)

    toClient.println(s);

    Program:

    //Browser.java

    51

  • 8/2/2019 web technology laboratory manual

    52/64

    import java.net.*;import java.io.*;

    public class Browser{public static void main(String[] args){

    String s;if(args.length!=3){System.out.println("Usage: java Browser host port file");System.exit(1);}try{int port = Integer.parseInt(args[1]);Socket server = new Socket(args[0],port);System.out.println("Connected to host" + server.getInetAddress());BufferedReader fromServer = new BufferedReader(newInputStreamReader(server.getInputStream()));

    PrintWriter toServer = new PrintWriter(server.getOutputStream(),true);toServer.println("GET"+args[2]+"HTTP/1.0");toServer.println("Host:"+args[0]+':'+args[1]);toServer.println();while(!(s=fromServer.readLine()).equals(""));while((s=fromServer.readLine())!= null)System.out.println(s);fromServer.close();toServer.close();server.close();}

    catch(Exception e){e.printStackTrace();}}}

    //Webserver.java

    import java.net.*;import java.io.*;import java.util.StringTokenizer;

    public class Webserver{public static void main(String[] args){String s;try{ServerSocket server = new ServerSocket(Integer.parseInt(args[0]));Socket client = server.accept();System.out.println("very simple web server connected on port"+args[0]);

    BufferedReader fromClient = new BufferedReader(newInputStreamReader(client.getInputStream()));

    52

  • 8/2/2019 web technology laboratory manual

    53/64

    PrintWriter toClient = new PrintWriter(client.getOutputStream(),true);s = fromClient.readLine();StringTokenizer tokens = new StringTokenizer(s);if(!(tokens.nextToken()).equals("GET")){toClient.println("HTTP/1.0 501 Not implemented");

    toClient.println();}else{String filename = tokens.nextToken();while(!(s = fromClient.readLine()).equals(""));BufferedReader file = new BufferedReader(new FileReader(filename));toClient.println("HTTP/1.0 200 OK");toClient.println("content type: text/plain");toClient.println();while((s=file.readLine())!=null)

    toClient.println(s);file.close();}fromClient.close();toClient.close();client.close();}catch(Exception e){ e.printStackTrace(); }}}

    Output:

    53

  • 8/2/2019 web technology laboratory manual

    54/64

    Result:

    Thus the implementation of HTTP protocol in java is successfully completed andverified.

    Ex No: 11Date: DOWNLOADING AN IMAGE FILE USING RMI

    54

  • 8/2/2019 web technology laboratory manual

    55/64

    Aim

    To develop a java program to download an image using Remote Method Invocation.

    Introduction:

    A distributed application is an application whose is distributed across multiplenetworked computers. Distributed architecture is based on the three tier architecture applicationdevelopment, where the front and namely the user interface is on one network and businessrules and the database on a different network. The models for developing distributedapplications that exist in the industry today are DCOM, RMI and CORBA. The distributedobject model used by java allows objects in one JVM and this is known as Remote MethodInvocation.

    General RMI Architecture:

    1. The server must first bind the name to the registry.2. The client lookup the server name in the registry to establish remote references.3. The stub serializes the parameters to skeleton; the skeleton invokes the remote method

    and serializes the result back to the stub.

    Procedure to develop a RMI system:

    Step 1:

    Defining remote interface to create a RMI application, the first step is defining of aremote interface between the Client and Server objects.The Remote interface must have the following properties:The interface must be public.The interface must extend the interface.java.rmi.Remote.Every methods declared in the interface must throw java.rmi.RemoteException.Other exceptions may also be thrown.

    Step 2:

    Develop the Implementation class. Create the implementation class by extendingjava.rmi.server.UnicastRemoteObject.

    UnicastRemoteObject.exportObject(new ServerRMI,port) this can be used in case theserver already extends some other class and we want that class to be the server class. The

    implementation class needs to override the remote interface methods.

    The java.rmi.server Package:This package implements several interfaces and classes that support both client and

    server aspects of RMI like a class implantation of the remote interface, client stub, serverskeleton and so on.

    Step 3:

    Develop the server program.The server must bind its name to the name registry. The client will look up the servername use java.rmi.Naming class to bind the server name to registry.

    Step 4:Develop the client program.

    55

  • 8/2/2019 web technology laboratory manual

    56/64

    In order for the client object to invoke methods on the server, it must first look up thename of the server object in the registry. Use the java.rmi.Naming class to lookup theserver name. Use the java.rmi.Naming class to lookup the servername.The server name is specified as URL in the format (rmi://host:port/name). Default RMI

    port is 1099.

    The name specified in the URL must exactly match the name with which the serverobject has bound to the registry. The remote method invocation is programmed using theremote interface reference_name.function_name.

    Step 5:

    Compiling of all the source files.

    Step 6:

    Generating stubs and skeleton.Now the stub and skeleton need to be generated using rmic (rmi compiler)>rmic implementation file

    Roles of SKELETON:

    Lives on server

    Receiver requests stub

    Talks to true remote object

    Delivers response to stub

    Roles of STUB:

    Lives on client

    Responsible for initiating a call

    Client proxy of the remote object Returns the result back to client

    Step 7:

    Starting the RMI registryThe rmiregistry must be stated using start rmiregistry. This step needs to be done before

    the server program starts as the implementation object has to be registered.

    Step 8:

    Run the server programOnce the registry is started, the server can be started and will be able to store itself in the

    register.>java ServerRMI

    Step 9:

    Run the client program>java ClientRMI

    The client program can now access the implementation program which is at the server. The fileis downloaded in the client system. For the client it seems as if the function call is on the samemachine.

    Program:

    56

  • 8/2/2019 web technology laboratory manual

    57/64

    //dInterface.java

    import java.rmi.*;public interface dInterface extends Remote{

    public byte[] download(String filename) throws RemoteException;}

    //dImplementation.java

    import java.rmi.*;import java.rmi.server.*;import java.io.*;

    public class dImplementation extends UnicastRemoteObject implements dInterface

    {public dImplementation() throws Exception{super();}public byte[] download(String filename){try{FileInputStream fis = new FileInputStream(filename);byte[] bytearray = new byte[fis.available()];

    fis.read(bytearray,0,bytearray.length);return bytearray;

    } catch (Exception e) {return null;}}}

    //ServerRMI.java

    import java.rmi.*;public class ServerRMI{public static void main(String args[]) throws Exception{dImplementation obj= new dImplementation();Naming.rebind("jj",obj);}}

    //ClientRMI.java

    57

  • 8/2/2019 web technology laboratory manual

    58/64

    import java.rmi.*;import java.io.*;

    public class ClientRMI{

    public static void main(String args[]) throws Exception{String serverurl="rmi://localhost/jj";dInterface dintf=(dInterface) Naming.lookup(serverurl);byte[] b=dintf.download(args[0]);FileOutputStream fos=new FileOutputStream(args[0]);fos.write(b);}}

    Output:

    58

  • 8/2/2019 web technology laboratory manual

    59/64

    Result

    Thus the program to download an image using Remote Method Invocation issuccessfully developed and is verified.

    Ex No: 12 IMPLEMENTING ARITHMETIC CALCULATION USINGDate: RMI-IIOP

    59

  • 8/2/2019 web technology laboratory manual

    60/64

    Aim

    To simulate the RMI-IIOP for implementing arithmetic operation using RMI-IIOP.

    ProcedureFor implementing this RMI-IIOP, 4 files are required namely

    i) ArithInterface.java

    ii) ArithImpl.java

    iii) ArithClient.java

    iv) ArithServer.java

    ArithInterfcae.java

    i) The remote interface must be declared public.

    ii) The data type of any remote object that is passed as an argument or return value

    must be declared as remote interface type.

    iii) Declare the methods for performing operations like add(), sub() and mult().

    //ArithInterface.javaimport java.rmi.Remote;

    public interface ArithInterface extends java.rmi.Remote{

    }

    ArithImpl.java

    i) Declare the implementation class with atleast one remote interface.

    ii) Define the constructor for the remote object.

    iii) Provide implementations for the methods that can be invoked remotely.

    ArithServer.java

    A Server class is the class which has the main method that creates an instance of the

    remote object implementation and binds that instance to a name in the Naming Service. The

    class that contains this main method could be the implementation class itself.

    ArithClient.java

    The Client application gets a reference to the remote object implementation from the

    60

  • 8/2/2019 web technology laboratory manual

    61/64

    Naming Service using Java Naming and Directory Interface(JNDI) calls.

    i) The Naming.lookup method takes java.lang.String value representing the name

    of the object to look up.

    Compilation

    1. Compile the remote object implementation.

    2. Use rmic to generate stubs and skeletons.

    3. Compile the source files

    javac *.javarmic iiop ArithImplstart orbd ORBIntialPort 1050

    4. Start the Server

    java -classpath .

    -Djava.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory-Djava.naming.provider.url=iiop://localhost:1050 HelloServer5. Start the client using the same syntax above.

    Program:

    //Arithserver.java

    import javax.naming.*;public class ArithServer {

    public static void main(String[] args) {try {

    // Step 1: Instantiate the Hello servantArithImpl arithRef = new ArithImpl();

    // Step 2: Publish the reference in the Naming Service// using JNDI APIContext initialNamingContext = new InitialContext();initialNamingContext.rebind("ArithService", arithRef );

    System.out.println("Hello Server: Ready...");

    } catch (Exception e) {System.out.println("Trouble: " + e);e.printStackTrace();

    }}

    }

    // Arithclient.java

    import java.rmi.*;

    import java.net.*;import javax.rmi.*;

    61

  • 8/2/2019 web technology laboratory manual

    62/64

    import java.util.Vector;import javax.naming.*;

    public class ArithClient {

    public static void main( String args[] ) {Context ic;Object objref;ArithInterface hi;

    try {ic = new InitialContext();

    // STEP 1: Get the Object reference from the Name Service// using JNDI call.

    objref = ic.lookup("ArithService");

    System.out.println("Client: Obtained a ref. to Arith server.");

    // STEP 2: Narrow the object reference to the concrete type and// invoke the method.

    hi = (ArithInterface) PortableRemoteObject.narrow(objref, ArithInterface.class);

    int result;result=hi.add(5,10);System.out.println("Add result is = "+result);

    result=hi.sub(5,10);System.out.println("Sub result is = "+result);

    result=hi.mul(5,10);System.out.println("Mul result is = "+result);

    }catch( Exception e ){

    System.err.println( "Exception " + e + "Caught" );

    e.printStackTrace( );return;}

    }}

    //ArithImpl.java

    import java.rmi.*;import javax.rmi.*;

    62

  • 8/2/2019 web technology laboratory manual

    63/64

    public class ArithImpl extends PortableRemoteObject implements ArithInterface {public ArithImpl() throws RemoteException {

    super();}

    public int add(int x,int y)throws RemoteException

    {return (x+y);

    }public int sub(int x,int y)throws RemoteException{

    return (x-y);}

    public int mul(int x,int y)throws RemoteException{

    return (x*y);}

    }

    //Arithinterface.java

    import java.rmi.*;

    public interface ArithInterface extends Remote {public int add(int x,int y)throws RemoteException;

    public int sub(int x,int y)throws RemoteException;public int mul(int x,int y)throws RemoteException;

    }

    Output:

    63

  • 8/2/2019 web technology laboratory manual

    64/64

    Result

    Thus the program to implement Arithmetic Operations using RMI-IIOP is successfully

    developed and is verified.