0% found this document useful (0 votes)
53 views34 pages

DT Lab Manual

The document outlines various practical experiments conducted in a Distributed Technologies Lab as part of a Master of Computer Applications program. It includes code examples for Java Remote Method Invocation (RMI) applications, JSP scriptlets, and XML transformations, along with explanations of database interactions and web page creation. The document serves as a record of the work done during the academic year 2021-2022.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views34 pages

DT Lab Manual

The document outlines various practical experiments conducted in a Distributed Technologies Lab as part of a Master of Computer Applications program. It includes code examples for Java Remote Method Invocation (RMI) applications, JSP scriptlets, and XML transformations, along with explanations of database interactions and web page creation. The document serves as a record of the work done during the academic year 2021-2022.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

MASTER OF COMPUTER APPLICATIONS

“Distributed Technologies Lab”

REG. NO :

SEMESTER - II

April– 2022
DEPARTMENT OF COMPUTER APPLICATIONS

SRINIVASAN COLLEGE OF ARTS & SCIENCE


(Approved by AICTE, New Delhi &Affiliated to Bharathidasan University, Tiruchirappalli)

(Recognized under the section 2(f) & 12(B) by UGC Act 1956)

PERAMBALUR-621 212.
DEPARTMENT OF COMPUTER APPLICATIONS

SRINIVASAN COLLEGE OF ARTS & SCIENCE


PERAMBALUR-621 212

CERTIFICATE

This is to certify that the bonafide record of the work done in


the computer laboratory during the academic year 2021-2022.

SUBMITTED BY

NAME : ________________________

REG.NO : ________________________

CLASS : ________________________

TITLE : ________________________

SEMESTER : ______________________

For The Practical Examination Held on ______________

STAFF IN-CHARGE HEAD OF THE DEPARTMENT

EXAMINERS:

1. 2.
INDEX

Page
S.No Date Experiment Signature
No
1. Remote Method Invocation

//Interface Program
import java.rmi.*;
public interface AddRem extends Remote
{
public int addNum(int a,int b) throws RemoteException;
}

//Implementation Program

import java.rmi.*;
import java.rmi.server.*;
public class AddRemImpl extends UnicastRemoteObject implements AddRem
{
public AddRemImpl() throws RemoteException{}
public int addNum(int a,int b)
{
return(a+b);
}
}

//Client Program

import java.rmi.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class AddClient
{
public static void main(String args[])
{
String host="localhost";
Scanner sc=new Scanner(System.in);
System.out.println("Enter First Value");
int a=sc.nextInt();
System.out.println("Enter Second Value");
int b=sc.nextInt();
try{
AddRem remobj=
(AddRem)Naming.lookup("rmi://"+host+"/AddRem");
System.out.println(remobj.addNum(a,b));
}
catch(Exception e) {
System.out.println(e);
}
}
}

//Server Program

import java.rmi.*;
import java.rmi.registry.*;
import java.net.*;
public class AddServer {
public static void main(String args[]) {
try {
AddRemImpl locobj=new AddRemImpl();
Naming.rebind("rmi:///AddRem",locobj); //addService object
is hosted with name AddService

}
catch(Exception e) {
System.out.println(e);
}
}
}
OutPut:
2. Java RMI - Database Application
We created a sample RMI application where a client invokes a method which
displays a GUI window (JavaFX).
In this chapter, we will take an example to see how a client program can retrieve the
records of a table in MySQL database residing on the server.
Assume we have a table named student_data in the database details as shown below.

Java RMI Database Application


Assume the name of the user is myuser and its password is password.

Creating a Student Class


Create a Student class with setter and getter methods as shown below.
public class Student implements java.io.Serializable
{
private int id, percent;
private String name, branch, email;
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getBranch() {
return branch;
}
public int getPercent() {
return percent;
}
public String getEmail() {
return email;
}
public void setID(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setBranch(String branch) {
this.branch = branch;
}
public void setPercent(int percent) {
this.percent = percent;
}
public void setEmail(String email) {
this.email = email;
}
}

Defining the Remote Interface


Define the remote interface. Here, we are defining a remote interface named Hello
with a method named getStudents () in it. This method returns a list which contains
the object of the class Student.
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.*;
// Creating Remote interface for our application
public interface Hello extends Remote {

public List<Student> getStudents() throws Exception;


}

Developing the Implementation Class


Create a class and implement the above created interface.
Here we are implementing the getStudents() method of the Remote interface. When
you invoke this method, it retrieves the records of a table named student_data. Sets
these values to the Student class using its setter methods, adds it to a list object and
returns that list.

import java.sql.*;
import java.util.*;
// Implementing the remote interface
public class ImplExample implements Hello {

// Implementing the interface method


public List<Student> getStudents() throws Exception {
List<Student> list = new ArrayList<Student>();

// JDBC driver name and database URL


String JDBC_DRIVER = "com.mysql.jdbc.Driver";
String DB_URL = "jdbc:mysql://localhost:3306/details";

// Database credentials
String USER = "myuser";
String PASS = "password";
Connection conn = null;
Statement stmt = null;
//Register JDBC driver
Class.forName("com.mysql.jdbc.Driver");
//Open a connection
System.out.println("Connecting to a selected database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
System.out.println("Connected database successfully...");
//Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM student_data";
ResultSet rs = stmt.executeQuery(sql);
//Extract data from result set
while(rs.next()) {
// Retrieve by column name
int id = rs.getInt("id");
String name = rs.getString("name");
String branch = rs.getString("branch");
int percent = rs.getInt("percentage");
String email = rs.getString("email");
// Setting the values
Student student = new Student();
student.setID(id);
student.setName(name);
student.setBranch(branch);
student.setPercent(percent);
student.setEmail(email);
list.add(student);
}
rs.close();
return list;
}}
Server Program
An RMI server program should implement the remote interface or extend the
implementation class. Here, we should create a remote object and bind it to the RMI
registry.
Following is the server program of this application. Here, we will extend the above
created class, create a remote object and register it to the RMI registry with the bind
name hello.

import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
public class Server extends ImplExample {
public Server() {}
public static void main(String args[]) {
try {
// Instantiating the implementation class
ImplExample obj = new ImplExample();
// Exporting the object of implementation class (
here we are exporting the remote object to the stub)
Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
// Binding the remote object (stub) in the registry
Registry registry = LocateRegistry.getRegistry();
registry.bind("Hello", stub);
System.err.println("Server ready");
} catch (Exception e) {
System.err.println("Server exception: " + e.toString());
e.printStackTrace();
}
}
}
Client Program
Following is the client program of this application. Here, we are fetching the remote
object and invoking the method named getStudents(). It retrieves the records of the
table from the list object and displays them.
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.*;
public class Client {
private Client() {}
public static void main(String[] args)throws Exception {
try {
// Getting the registry
Registry registry = LocateRegistry.getRegistry(null);
// Looking up the registry for the remote object
Hello stub = (Hello) registry.lookup("Hello");
// Calling the remote method using the obtained object
List<Student> list = (List)stub.getStudents();
for (Student s:list)v {
// System.out.println("bc "+s.getBranch());
System.out.println("ID: " + s.getId());
System.out.println("name: " + s.getName());
System.out.println("branch: " + s.getBranch());
System.out.println("percent: " + s.getPercent());
System.out.println("email: " + s.getEmail());
}
System.err.println("Client exception: " + e.toString());
e.printStackTrace();
}} }
// System.out.println(list);
} catch (Exception e) {
System.err.println("Client exception: " + e.toString());
e.printStackTrace(); } } }
3. Webpages using JSP Scriptlet
UserDetails.html
<html>
<title>Scriptlet Tag</title>
<head>
<style type="text/css">
h1 {
color: green;
text-align: center;
}
label {
font-size: 22px;
color: green;
}
</style>
</head>
<body>
<h1>Register User Details</h1>
<form action="User.jsp">
<table>
<tr>
<td><label for="register_name">Enter name:</label></td>
<td><input type="text" name="name" value="" id="register_name"
style="width: 160px" /></td>
</tr>
<tr>
<td><label for="register_password"">Enter password:</label></td>
<td><input type="password" name="password"
id="register_password" style="width: 160px" /></td>
</tr>
<tr>
<td><label for="register_email">Enter Email:</label></td>
<td><input type="email" name="email" value=""
id="register_email" style="width: 160px" /></td>
</tr>
<tr>
<td><label for="register_gender">Enter Gender:</label></td>
<td><input type="radio" name="gender" value="male" /><label
for="register_gendermale">male</label><input type="radio"
name="gender" id="register_genderfemale" value="female" /><label
for="register_genderfemale">female</label></td>
</tr>
<tr>
<td><label for="register_country">Select Country:</label></td>
<td><select name="country" style="width: 160px">
<option value="india">India</option>
<option value="pakistan">US</option>
<option value="africa">Brazil</option>
<option value="china">England</option>
<option value="other">Italy</option>
<option value="other">Others</option>
</select></td>
</tr>
<tr>
<td colspan="2"><div align="right">
<input type="submit" id="register_0" value="Sign Up" />
</div></td>
</tr>
</table>
</form>
</body>
</html>
User.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<!-- CSS Styles -->
<style type="text/css">
h1 {
color: red;
text-align: center;
}
p{
color: green;
font-size: 25px;
border: solid 3px blue;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Scriptlet Tag</title>
</head>
<body>
<h1>Well Come to My Application Form</h1>
<p>
<!--scriptlet tag -->
<%
//getting all HTML parameters
String name = request.getParameter("name");
String email = request.getParameter("email");
String gender = request.getParameter("gender");
String country = request.getParameter("country");
//out is implicit object of JSP
out.print("My Name is " + name+"<br>");
out.print("My Email is " + email+"<br>");
out.print("My Gender is " + gender+"<br>");
out.print("My Country is " + country);
%>
</p>
</body>
</html>

Output
4. Webpage using JSP of java beans

Test.java
package Action;
public class Test {
private String message = "No message specified";
public String getMessage() {
return (message);
}
public void setMessage(String message) {
this.message = message;
}
}

index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Using JavaBeans in JSP</title>
</head>
<body>
<h2>Using JavaBeans in JSP</h2>
<jsp:useBean id="test" class="Action.Test" />
<jsp:setProperty name="test" property="message" value="Hello JSP..." />
<p>Got message....</p>
<jsp:getProperty name="test" property="message" />
</body>
</html>
Output:
5. Performing XML transformation using XML and XSL coding
XSLT stands for Extensible Stylesheet Language Transformation.
Table.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="rule.css"?>
<tables>
<m:table xmlns:m=""http://www.google.co.in">
<m:tr>
<m:td>Apple</m:td>
<m:td>Banana</m:td>
</m:tr>
</m:table>
<n:table xmlns:m=""http://www.yahoo.co.in">
<n:height>100</n:height>
<n:width>150</n:width>
</n:table>
</tables>

Students.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl "href="Rule.xsl" ?>
<student>
<s>
<name> Divyank Singh Sikarwar </name>
<branch> CSE</branch>
<age>18</age>
<city> Agra </city>
</s>
<s>
<name> Aniket Chauhan </name>
<branch> CSE</branch>
<age> 20</age>
<city> Shahjahanpur </city>
</s>
<s>
<name> Simran Agarwal</name>
<branch> CSE</branch>
<age> 23</age>
<city> Buland Shar</city>
</s>
<s>
<name> Abhay Chauhan</name>
<branch> CSE</branch>
<age> 17</age>
<city> Shahjahanpur</city>
</s>
<s>
<name> Himanshu Bhatia</name>
<branch> IT</branch>
<age> 25</age>
<city> Indore</city>
</s>
</student>

Rule.xsl

<?xml version="1.0" encoding="UTF-8"?>


<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h1 align="center">Students' Basic Details</h1>
<table border="3" align="center" >
<tr>
<th>Name</th>
<th>Branch</th>
<th>Age</th>
<th>City</th>
</tr>
<xsl:for-each select="student/s">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="branch"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="city"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output :
6. Create XML Schema
employee.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.javatpoint.com"
xmlns="http://www.javatpoint.com"
elementFormDefault="qualified">
<xs:element name="employee">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

employee.xml

<?xml version="1.0"?>
<employee
xmlns="http://www.javatpoint.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.javatpoint.com employee.xsd">
<firstname>vimal</firstname>
<lastname>jaiswal</lastname>
<email>[email protected]</email>
</employee>
7. Creation of a table and insertion of a few records using Disconnected Access.
Create Form:

Imports System.Data.OleDb
Public Class mobiles
Dim con As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim st As String
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source= azhar.mdb")
con.Open()
st = "insert into mo values('" & Trim(TextBox1.Text) & "','" &
Trim(ComboBox1.Text) & "','" & Trim(TextBox3.Text) & "','" & Trim(TextBox5.Text) &
"')"
cmd = New OleDbCommand(st, con)
cmd.ExecuteReader()
MsgBox("Record Saved.....")

Catch ex As Exception
MsgBox(Err.Description)
End Try
TextBox1.Text = ""
ComboBox1.Text = ""
TextBox3.Text = ""
End Sub
End Class

Create another one Form:

Imports System.Data.OleDb
Public Class mobsale
Dim con As OleDbConnection
Dim cmd, cmd1, cmd2, cmd3 As OleDbCommand
Dim dr, dr1, dr2 As OleDbDataReader
Private Sub FindBtn_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
Dim st2, a As String
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source= azhar.mdb")
con.Open()
a = InputBox("Enter the mobile no")
st2 = "select * from MO1 where MONO='" & Trim(a) & "'"
cmd1 = New OleDbCommand(st2, con)
dr1 = cmd1.ExecuteReader
If dr1.Read Then
TextBox1.Text = dr1(0)
ComboBox1.Text = dr1(1)
TextBox3.Text = dr1(2)
Else
MsgBox("not found")
End If
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub

Private Sub Salesbtn_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Dim st3, st4 As String
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source= azhar.mdb")
con.Open()
st3 = "insert into mosale values('" & Trim(TextBox4.Text) & "','" &
Trim(TextBox1.Text) & "','" & Trim(ComboBox1.Text) & "','" & Trim(TextBox3.Text) &
"','" & Trim(TextBox2.Text) & "')"
cmd2 = New OleDbCommand(st3, con)
cmd2.ExecuteNonQuery()
st4 = "delete from mo1 where mono='" & Trim(TextBox1.Text) & "'"
cmd3 = New OleDbCommand(st4, con)
cmd3.ExecuteNonQuery()
MsgBox("Successfully Sold")
Catch ex As Exception
MsgBox(Err.Description)
End Try
TextBox1.Text = ""
TextBox2.Text = ""
ComboBox1.Text = ""
TextBox3.Text = ""
End Sub
End Class
8. Viewing records using GridView, Details View, Form View Controls.
 Add the Windows form
 Drag and Drop the Datagridview control from toolbox.
 Create a database and create a table in Ms-Access.

Imports System.Data.OleDb
Public Class mobilesalrpt
Dim con As OleDbConnection
Dim cmd, cmd1 As OleDbCommand
Dim dr, dr1 As OleDbDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim st, a As String
Try
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source= d:\ex1\azhar.mdb")
con.Open()
a = InputBox("Enter the Date")
st = "select * from mosale where date='" & Trim(a) & "'"
DataGridView1.Show()
DataGridView1.RowCount
cmd1 = New OleDbCommand(st, con)
dr = cmd1.ExecuteReader()
DataGridView1.ColumnCount = 5
While (dr.Read)
DataGridView1.Rows.Add(dr(0), dr(1), dr(2), dr(3), dr(4))
End While
con.Close()
Catch ex As Exception
MsgBox(Err.Description)
End Try
End Sub
End Class
9. Generation of a crystal report from an existing database.
Add the Crystal Report from toolbox

 Go to Database Field ->


 Right Click Database Expert ->
 Click .NET Object ->
 Select the table

 Add the window form


 Drag and drop crystal report viewer
public Class mobilesalesfrm
Private Sub CrystalReportViewer1_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles CrystalReportViewer1.Load
Dim cr As New mobilesalesrpt
CrystalReportViewer1.ReportSource = cr
Me.WindowState = FormWindowState.Maximized
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e


As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
LinkLabel1.LinkClicked
Dim M As New MAIN
M.Show()
Me.Hide()
End Sub
End Class
10. Web page that uses of Ad Rotator Control.
Go to ASP.NET Website Project

Create the Ad XML file


XMLFile.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Banners/468X60_add.gif</ImageUrl>

NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</Navigat
eUrl>
<AlternateText>Advertisement</AlternateText>
<Impressions>100</Impressions>
<Keyword>Header</Keyword>
<Category>Script</Category>
</Ad>
<Ad>
<ImageUrl>~/Banners/468X60_Consultant.gif</ImageUrl>

<NavigateUrl>http://www.mindcracker.com/Consultants/</NavigateUrl>
<AlternateText>Advertisement</AlternateText>
<Impressions>100</Impressions>
<Keyword>Header</Keyword>
<Category>Script</Category>
</Ad>
<Ad>
<ImageUrl>~/Banners/468X60_Employer.gif</ImageUrl>

<NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</Naviga
teUrl>
<AlternateText>Advertisement</AlternateText>
<Impressions>100</Impressions>
<Keyword>Header</Keyword>
<Category>Script</Category>
</Ad>
<Ad>
<ImageUrl>~/Banners/468X60_Jobseeker.gif</ImageUrl>
<NavigateUrl>http://www.mindcracker.com/Jobs/</NavigateUrl>
<AlternateText>Advertisement</AlternateText>
<Impressions>100</Impressions>
<Keyword>Header</Keyword>
<Category>Script</Category>
</Ad>
<Ad>
<ImageUrl>~/Banners/468X60_Recruiter.gif</ImageUrl>

<NavigateUrl>http://www.Mindcracker.com/Registration/Register.aspx</Naviga
teUrl>
<AlternateText>Advertisement</AlternateText>
<Impressions>100</Impressions>
<Keyword>Header</Keyword>
<Category>Script</Category>
</Ad>
</Advertisements>

Bind XML File


set the AdvertisementFile property of the AdRotator and the value is our Ad XML
file we created earlier.

<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/Advertise.x


ml" Target="_blank" />

Build and run


Output

After refreshing page then you will see a different image. The images are loaded
randomly.

You might also like