sreebrothers.blogspot.com

Welcome to sreebrothers.blogspot.com - A blog that helps engineering students, particularly for Computer Science and Engineering students. Are you a CSE student? Are you finding any study materials? This is your gateway to seek your study materials. This website offers various resources for the students pursuing their courses in affiliated college of Anna University. This included a number of resources in various subjects such as Programming Paradigms, Web Technology, Internet Programming Lab, Java Lab, and so on. In addition to these resources, it offers some university updates, and also included some previous year university question papers. Keep visiting this blog for new updates......

"If someone feels that they had never made a mistake in their life, then it means they had never tried a new things in their life"
Albert Einstein---

Quick Links

CS6703 - Grid and Cloud Computing (Question Bank)

Part-A

1. What are the three new computing paradigms?
2. What is IoT?
3. What is GPU computing?
4. What is virtual machine?
5. What is virtualization middleware?
6. What are the three cloud service models?
7. What is OGSA?
8. What is OGSI?
9. List down the functionality requirements of a typical grid system
10. Distinguish between static data replication and dynamic data replication
11. What are the grid data access models?
12. Differentiate striped and parallel data transfer
13. What is virtualization?
14. List down the advantages of cloud computing
15. Draw the architecture of a computer system after virtualization
16. List down the various virtualization levels of a computer system
17. What is memory virtualization?
18. What is I/O virtualization?
19. What is hypervisor? What are the two types of hypervisor architecture?
20. What is para virtualization?
21. What is virtual cluster?
22. What are the steps in live migration of virtual machines?
23. What is data center automation?
24. What are the components of hadoop?
25. What is MapReduce?
26. What are the steps in the workflow of MapReduce process?
27. What are the three components contribute in running a job in hadoop system?
28. List down the features of HDFS
29. What are the various operations of HDFS?
30. List down some security issues in the grid environment
31. What are the three challenges to establish the trust in grid environment?
32. What is PKI?
33. Distinguish authorization and authentication
34. List down the three authorization models
35.  What are the functional layers of GSI?
36. What is delegation?
37. List down some security issues related to cloud infrastructure

Part-B

1. Explain in detail the various architecture of virtual machine
2. Write short notes on: (i) Clusters of cooperative computers (ii) Grid computing infrastructure (iii) SOA
3. Write in detail the grid architecture and its elements
4. Explain in detail about OGSA architecture with neat illustration
5. Brief about data intensive grid service models
6. Explain in detail various categories of grid services
7. Write in detail about OGSI
8. Explain in detail various cloud deployment models
9. Explain in detail various cloud  service models
10. Explain in detail the various structure of virtualization with neat figure
11. Write in detail the GT4 architecture and its components
12. Explain in detail the various components of hadoop framework
13. Explain in detail about hadoop map and reduce functions with suitable example
14.  Write short notes on HDFS with its neat architecture
15. Write in detail grid trust models
16. Write short notes on grid security infrastructure
17. Write short notes on cloud security infrastructure

EC8381 - Fundamentals of Data Structures in C Lab

1. Looping and Arrays

a) Multiplication Table Using for Loop

#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,mult;
 clrscr();
 printf("Enter a number:\n");
 scanf("%d",&n);
 for(i=1;i<=10;i++)
 {
  mult=n*i;
  printf("%d*%d=%d\n",n,i,mult);
 }
 getch();
}

b) Sum of Even Numbers Using while Loop



#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i=0,sum=0;
 clrscr();
 printf("Enter the limit:\n");
 scanf("%d",&n);
 printf("Sum of Even Numbers from 0 to %d\n",n);
 while(i<=n)
 {
  sum=sum+i;
  i=i+2;
 }
 printf("%d",sum);
 getch();
}

c) Sum of Digits Using while Loop



#include<stdio.h>
#include<conio.h>
void main()
{
 int n,sum=0,rem;
 clrscr();
 printf("Enter a Number:\n");
 scanf("%d",&n);
 while(n!=0)
 {
  rem=n%10;
  sum=sum+rem;
  n=n/10;
 }
 printf("Sum Of Digit=%d",sum);
 getch();
}

d) Determine Whether the Number is Palindrome or not



#include<stdio.h>
#include<conio.h>
void main()
{   
 int n1,n2,digit,rev=0;
 clrscr();
 printf("Enter a number:\n");
 scanf("%d",&n1);
 n2=n1;
 while(n2!=0)
 {
  digit=n2%10;
  rev=(rev*10)+digit;
  n2=n2/10;
 }
 if(n1==rev)
 {
  printf("The number is a palindrome");
 }
 else
 {
  printf("The number is not a palindrome");
 }
 getch();
}

e) Determine Whether the Number is Armstrong or not



#include<stdio.h>
#include<conio.h>
void main()
{
 int n1,n2,rem,sum=0;
 clrscr();
 printf("\nEnter a Number:\n");
 scanf("%d",&n1);
 n2=n1;
 while(n2!=0)
 {
  rem=n2%10;
  sum=sum+(rem*rem*rem);
  n2=n2/10;
 }
 if(sum==n1)
 {
  printf("Armstrong Number");
 }
 else
 {
  printf("Not an Armstrong Number ");
 }
 getch();
}

f) Generating Prime Numbers



#include<stdio.h>
#include<conio.h>
void main()
{
 int no,i,count,remainder;
 clrscr();
 for(no=2;no<=50;no++)
 {
  i=1,count=0;
  while(i<=no)
  {
   remainder=no%i;
   if(remainder==0)
   {
    count=count+1;
   }
   i++;
  }
  if(count==2)
  {
   printf("%d\n",no);
  }
 }
 getch();
}

g) Array Sorting



#include<stdio.h>
#include<conio.h>
void main()
{
 int n,i,j,a[30],temp;
 clrscr();
 printf("Enter the limit:\n");
 scanf("%d",&n);
 printf("Enter the array elements:\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 for(i=0;i<n;i++)
 {
  for(j=i+1;j<n;j++)
  {
   if(a[i]>a[j])
   {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
   }
  }
 }
 printf("Array Elements in Ascending Order:\n");
 for(i=0;i<n;i++)
 {
  printf("%d\n",a[i]);
 }
 for(i=0;i<n;i++)
 {
  for(j=i+1;j<n;j++)
  {
   if(a[i]<a[j])
   {
    temp=a[i];
    a[i]=a[j];
    a[j]=temp;
   }
  }
 }
 printf("Array Elements in Descending Order:\n");
 for(i=0;i<n;i++)
 {
  printf("%d\n",a[i]);
 }
 getch();
}

2. String Operations



#include<stdio.h>
#include<conio.h>
void main()
{
 char str1[30],str2[30];
 clrscr();
 printf("Enter string1:");
 gets(str1);
 printf("Enter string2:");
 gets(str2);
 printf("\nLength of string1:%d",strlen(str1));
 printf("\nLength of string2:%d",strlen(str2));
 strcat(str1,str2);
 printf("\nConcatenated String:");
 puts(str1);
 getch();
}

3. Structures and Pointers


a) Student Details Using Structure



#include<stdio.h>
#include<conio.h>
struct stud
{
 char name[25];
 int rno;
 int m1;
 int m2;
 int m3;
 int total;
 float avg;
};
struct stud s[10];
void main()
{
 int n,i;
 clrscr();
 printf("Enter the limit:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("Enter the name,rollno,and marks:\n");
  scanf("%s",&s[i].name);
  scanf("%d",&s[i].rno);
  scanf("%d",&s[i].m1);
  scanf("%d",&s[i].m2);
  scanf("%d",&s[i].m3);
  s[i].total=s[i].m1+s[i].m2+s[i].m3;
  s[i].avg=s[i].total/3;
 }
 printf("\nSTUDENT DETAILS\n\n");
 printf("Name\tRollNo\tMark1\tMark2\tMark3\tTotal\tAverage\n");
 for(i=0;i<n;i++)
 {
 printf("%s\t%d\t%d\t%d\t%d\t%d\t%f\n",s[i].name,s[i].rno,s[i].m1,s[i].m2,s[i].m3,s[i].total,s[i].avg);
 }
 getch();
}

b) Simple Program Using Pointer



#include <stdio.h>
void main()
{
 int *ptr;
 int c = 33;
 ptr= &c;
 printf("Value of variable c is: %d", c);
 printf("\nValue of variable c is: %d", *ptr);
 printf("\nAddress of variable c is: %p", &c);
 printf("\nAddress of variable c is: %p", ptr);
 printf("\nAddress of pointer ptr is: %p", &ptr);
}

c) Swapping Using Pointer

#include <stdio.h>
void main()
{
 int x, y, *a, *b, temp;
 printf("Enter the value of x and y\n");
 scanf("%d%d", &x, &y);
 printf("Before Swapping x = %d, y = %d\n", x, y);
 a = &x;
 b = &y;
 temp = *b;
 *b = *a;
 *a = temp;
 printf("After Swapping x = %d, y = %d\n", x, y);
}

4. Dynamic Memory Allocations

a) Sum of n Numbers Using malloc() Function

#include <stdio.h>
#include <stdlib.h>
void main()
{
 int num, i, *ptr, sum = 0;
 printf("Enter number of elements: ");
 scanf("%d", &num);
 ptr = (int*) malloc(num * sizeof(int));
 if(ptr == NULL)                   
 {
  printf("Error! memory not allocated.");
  exit(0);
 }
 printf("Enter the elements ");
 for(i = 0; i < num; i++)
 {
  scanf("%d", ptr + i);
  sum = sum + *(ptr + i);
 }
 printf("Sum = %d", sum);
 free(ptr);
}

b) Sum of n Numbers Using calloc() Function

#include <stdio.h>
#include <stdlib.h>
void main()
{
 int num, i, *ptr, sum = 0;
 printf("Enter number of elements: ");
 scanf("%d", &num);
 ptr = (int*) calloc(num, sizeof(int));
 if(ptr == NULL)
 {
  printf("Error! memory not allocated.");
  exit(0);
 }
 printf("Enter elements of array: ");
 for(i = 0; i < num; i++)
 {
  scanf("%d", ptr + i);
  sum = sum + *(ptr + i);
 }
 printf("Sum = %d", sum);
 free(ptr);
}

c) Reallocation of Memory Using realloc() Function


#include <stdio.h>
#include <stdlib.h>
void main()
{
 int *ptr, i , n1, n2;
 printf("Enter size of array:");
 scanf("%d", &n1);
 ptr = (int*) malloc(n1 * sizeof(int));
 printf("Address of previously allocated memory: ");
 for(i = 0; i < n1; ++i)
 printf("%u\t",ptr + i);
 printf("\nEnter new size of array: ");
 scanf("%d", &n2);
 ptr = realloc(ptr, n2);
 printf("Address of Reallocated memory: ");
 for(i = 0; i < n2; ++i)
 printf("%u\t", ptr + i);
}

5. Stack

a) Array Implementation of Stack

#include<stdio.h>
int stack[100],choice,n,top,x,i;
void push(void);
void pop(void);
void display(void);
void main()
{
 top=-1;
 printf("ARRAY IMPLEMENTATION OF STACK\n");
 printf("Enter the size of Stack [MAX=100]:");
 scanf("%d",&n);
 printf("1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT");
 do
 {
  printf("\nEnter the Choice:");
  scanf("%d",&choice);
  switch(choice)
  {
   case 1:
   push();
   break;
   case 2:
   pop();
   break;
   case 3:
   display();
   break;
   case 4:
   break;
   default:
   printf ("Please Enter a Valid Choice(1/2/3/4)");   
  }
 }
 while(choice!=4);
}
void push()
{
 if(top>=n-1)
 {
  printf("Stack is over flow"); 
 }
 else
 {
  printf("Enter a value to be inserted:");
  scanf("%d",&x);
  top++;
  stack[top]=x;
 }
}
void pop()
{
 if(top<=-1)
 {
  printf("Stack is under flow");
 }
 else
 {
  printf("The popped elements is %d",stack[top]);
  top--;
 }
}
void display()
{
 if(top>=0)
 {
  printf("The elements in Stack");
  for(i=top; i>=0; i--)
  printf("\n%d",stack[i]);
 }
 else
 {
  printf("The Stack is empty");
 }
}

b) Linked List Implementation of Stack

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct Node
{
 int data;
 struct Node *next;
}
*top = NULL;
int choice, value;
void push();
void pop();
void display();
void main()
{
 printf("LINKED LIST IMPLEMENTATION OF STACK\n");
 printf("1.Push\n2.Pop\n3.Display\n4.Exit");
 while(choice!=4)
 {
  printf("Enter your choice: ");
  scanf("%d",&choice);
  switch(choice)
  {
   case 1:
   push();
   break;
   case 2:
   pop();
   break;
   case 3:
   display();
   break;
   case 4:
   exit(0);
   default:
   printf("Wrong Choice!! Please Enter a Valid Choice(1/2/3/4)\n");
  }
 }
}
void push()
{
 printf("Enter the value to be inserted: ");
 scanf("%d", &value);
 struct Node *newNode;
 newNode = (struct Node*)malloc(sizeof(struct Node));
 newNode->data = value;
 if(top == NULL)
 {
  newNode->next = NULL;
 }
 else
 {
  newNode->next = top;
 }
 top = newNode;
 printf("Insertion is Success!!!\n");
}
void pop()
{
 if(top == NULL)
 {
  printf("Stack is Empty!!!\n");
 }
 else
 {
  struct Node *temp = top;
  printf("Deleted element: %d\n", temp->data);
  top = temp->next;
  free(temp);
 }
}
void display()
{
 if(top == NULL)
 {
  printf("Stack is Empty!!!\n");
 }
 else
 {
  struct Node *temp = top;
  while(temp->next != NULL)
  {
   printf("%d--->",temp->data);
   temp = temp -> next;
  }
  printf("%d--->NULL\n",temp->data);
 }
}

6. Queue

a) Array Implementation of Queue

#include<stdio.h>
#include<conio.h>
#define n 100
int queue[n],ch,front=0,rear=0,i,j=1,x=n;
void enqueue(void);
void dequeue(void);
void display(void);
void main()
{
 printf("ARRAY IMPLEMENTATION OF QUEUE");
 printf("\n1.Enqueue \n2.Dequeue \n3.Display \n4.Exit\n");
 do
 {
  printf("Enter the Choice:");
  scanf("%d",&ch);
  switch(ch)
  {
   case 1:
   enqueue();
   break;
   case 2:
   dequeue();
   break;
   case 3:
   display();
   break;
   case 4:
   break;
   default:
   printf("Wrong Choice!! Please Enter a Valid Choice(1/2/3/4)\n");
  }
 }
 while(ch!=4);
}
void enqueue()
{
 if(rear==x)
 {
  printf("Queue is Full\n");
 }
 else
 {
  printf("Enter the value to be inserted:");
  scanf("%d",&queue[rear++]);
 }
}
void dequeue()
{
 if(front==rear)
 {
  printf("Queue is empty\n");
 }
 else
 {
  printf("Deleted Element is %d\n",queue[front++]);
  x++;
 }
}
void display()
{
 if(front==rear)
 {
  printf("Queue is Empty\n");
 }
 else
 {
  printf("Queue Elements are:\n");
  for(i=front; i<rear; i++)
  {
   printf("%d\n",queue[i]);
  }
 }
}

b) Linked List Implementation of Queue

#include<stdio.h>
#include<conio.h>
struct Node
{
 int data;
 struct Node *next;
}*front = NULL,*rear = NULL;
void enqueue(void);
void dequeue(void);
void display(void);
int choice, value;
void main()
{
 printf("Linked List Implementation of Queue\n");
 printf("\n1.Enqueue \n2.Dequeue \n3.Display \n4.Exit\n");
 do
 {
  printf("Enter your choice: ");
  scanf("%d",&choice);
  switch(choice)
  {
   case 1:
   enqueue();
   break;
   case 2:
   dequeue();
   break;
   case 3:
   display();
   break;
   case 4:
   break;
   default: printf("Please Enter a Valid Choice(1/2/3/4\n");
  }
 }
 while(choice!=4);
}
void enqueue()
{
 printf("Enter the value to be insert: ");
 scanf("%d", &value);
 struct Node *newNode;
 newNode = (struct Node*)malloc(sizeof(struct Node));
 newNode->data = value;
 newNode -> next = NULL;
 if(front == NULL)
 front = rear = newNode;
 else
 {
  rear -> next = newNode;
  rear = newNode;
 }
 printf("Insertion is Success!\n");
}
void dequeue()
{
 if(front == NULL)
 printf("Queue is Empty\n");
 else
 {
  struct Node *temp = front;
  front = front -> next;
  printf("Deleted element: %d\n", temp->data);
  free(temp);
 }
}
void display()
{
 if(front == NULL)
 printf("Queue is Empty!\n");
 else
 {
  struct Node *temp = front;
  while(temp->next != NULL)
  {
   printf("%d--->",temp->data);
   temp = temp -> next;
  }
  printf("%d--->NULL\n",temp->data);
 }
}

7. Application of Stack (Reverse a String)

#include <stdio.h>
#include <string.h>
#define max 100
int top,stack[max];
void push(char);
void pop();
void main()
{
 char str[]="INDIA";
 int len = strlen(str);
 int i;
 for(i=0;i<len;i++)
 {
  push(str[i]);
 }
 for(i=0;i<len;i++)
 {
  pop();
 }
}
void push(char x)
{
 if(top == max-1)
 {
  printf("stack overflow");
 }
 else
 {
  stack[++top]=x;
 }
} 
void pop()
{
 printf("%c",stack[top--]);
}

8. Implementation of Tree Traversals

#include<stdio.h>
#include<stdlib.h>
struct node
{
 int data;
 struct node* left;
 struct node* right;
};
struct node* newNode(int data)
{
 struct node* node = (struct node*)malloc(sizeof(struct node));
 node->data = data;
 node->left = NULL;
 node->right = NULL;
 return(node);
}
void printPostorder(struct node* node)
{
 if (node == NULL)
 return;
 printPostorder(node->left);
 printPostorder(node->right);
 printf("%d ", node->data);
}
void printInorder(struct node* node)
{
 if (node == NULL)
 return;
 printInorder(node->left);
 printf("%d ", node->data);
 printInorder(node->right);
}
void printPreorder(struct node* node)
{
 if (node == NULL)
 return;
 printf("%d ", node->data);
 printPreorder(node->left);
 printPreorder(node->right);
} 
void main()
{
 struct node *root = newNode(1);
 root->left = newNode(2);
 root->right = newNode(3);
 root->left->left = newNode(4);
 root->left->right = newNode(5);
 printf("Preorder traversal of binary tree is: ");
 printPreorder(root);
 printf("\nInorder traversal of binary tree is: ");
 printInorder(root);
 printf("\nPostorder traversal of binary tree is: ");
 printPostorder(root);
}

9. Implementation Binary Search Tree

#include<stdio.h>
#include<stdlib.h>
struct node
{
 int key;
 struct node *left, *right;
};
struct node *newNode(int item)
{
 struct node *temp =  (struct node *)malloc(sizeof(struct node));
 temp->key = item;
 temp->left = temp->right = NULL;
 return temp;
}
void inorder(struct node *root)
{
 if (root != NULL)
 {
  inorder(root->left);
  printf("%d \n", root->key);
  inorder(root->right);
 }
}
struct node* insert(struct node* node, int key)
{
 if (node == NULL)
 {
  return newNode(key);
 }
 if (key < node->key)
 {
  node->left  = insert(node->left, key);
 }
 else if (key > node->key)
 {
  node->right = insert(node->right, key);
 } 
 return node;
}
void main()
{
 struct node *root = NULL;
 root = insert(root, 50);
 insert(root, 30);
 insert(root, 20);
 insert(root, 40);
 insert(root, 70);
 insert(root, 60);
 insert(root, 80);
 inorder(root);
}

10. Searching

a) Implementation of Linear Search

#include<stdio.h>
void main()
{
  int a[100], search, i, n;
  printf("Enter the number of elements: ");
  scanf("%d", &n);
  printf("Enter %d elements\n", n);
  for (i = 0; i < n; i++)
  scanf("%d", &a[i]);
  printf("Enter a number to search\n");
  scanf("%d", &search);
  for (i = 0; i < n; i++)
  {
   if (a[i] == search)
   {
    printf("%d is present at location %d\n", search, i+1);
    break;
   }
  }
  if (i == n)
  printf("%d is not present in the array\n", search);
}

b) Implementation of Binary Search

#include<stdio.h>
#include<conio.h>
void main()
{
 int n, i, j, a[50], temp, search, first, last, middle;
 printf("Enter total number of elements :");
 scanf("%d",&n);
 printf("Enter %d elements in ascending order:\n", n);
 for (i=0; i<n; i++)
 {
  scanf("%d",&a[i]);
 }
 printf("Enter a number to find :");
 scanf("%d", &search);
 first = 0;
 last = n-1;
 middle = (first+last)/2;
 while (first <= last)
 {
  if(a[middle] < search)
  {
   first = middle + 1;
  }
  else if(a[middle] == search)
  {
   printf("%d is found at location %d\n", search, middle+1);
   break;
  }
  else
  {
   last = middle - 1;
  }
  middle = (first + last)/2;
 }
 if(first > last)
 {
  printf("%d is not present in the list",search);
 }
}

11. Sorting

a) Implementation of Insertion Sort

#include<stdio.h>
void main()
{
 int i,j,n,temp,a[30];
 printf("Enter the number of elements:");
 scanf("%d",&n);
 printf("Enter the elements\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 for(i=1;i<=n-1;i++)
 {
  temp=a[i];
  j=i-1;
  while((temp<a[j])&&(j>=0))
  {
   a[j+1]=a[j];
   j=j-1;
  }
  a[j+1]=temp;
 }
 printf("Elements after sorting\n");
 for(i=0;i<n;i++)
 {
  printf("%d\n",a[i]);
 }
}

b) Implementation of Bubble Sort

#include<stdio.h>
void main()
{
 int a[50],n,i,j,temp;
 printf("Enter the number of elements: ");
 scanf("%d",&n);
 printf("Enter the elements:\n");
 for(i=0;i<n;++i)
 {
  scanf("%d",&a[i]);
 }
 for(i=1;i<n;++i)
 {
  for(j=0;j<(n-i);++j)
  {
   if(a[j]>a[j+1])
   {
    temp=a[j];
    a[j]=a[j+1];
    a[j+1]=temp;
   }
  }
 }
 printf("Elements after sorting:\n");
 for(i=0;i<n;++i)
 {
  printf("%d\n",a[i]);
 }
}

c) Implementation of Quick Sort

#include<stdio.h>
void quick_sort(int a[20],int,int);
void main()
{
 int a[20],n,i;
 printf("Enter the number of elements: ");
 scanf("%d",&n);
 printf("Enter %d elements:\n",n);
 for(i=0 ; i<n ; i++)
 {
  scanf("%d",&a[i]);
 }
 quick_sort(a,0,n-1);
 printf("Elements after sorting:\n");
 for(i=0 ; i<n ; i++)
 {
  printf("%d\n",a[i]);
 }
}
void quick_sort(int a[20],int low,int high)
{
 int pivot,j,temp,i;
 if(low<high)
 {
  pivot = low;
  i = low;
  j = high;
  while(i<j)
  {
   while((a[i]<=a[pivot])&&(i<high))
   {
    i++;
   }
   while(a[j]>a[pivot])
   {
    j--;
   }
   if(i<j)
   {
     temp=a[i];
     a[i]=a[j];
     a[j]=temp;
   }
  }
  temp=a[pivot];
  a[pivot]=a[j];
  a[j]=temp;
  quick_sort(a,low,j-1);
  quick_sort(a,j+1,high);
 }
}

d) Implementation of Merge Sort

#include<stdio.h>
void mergesort(int a[],int i,int j);
void merge(int a[],int i1,int j1,int i2,int j2);
void main()
{
 int a[30],n,i;
 printf("Enter the number of elements:");
 scanf("%d",&n);
 printf("Enter the elements:\n");
 for(i=0;i<n;i++)
 {
  scanf("%d",&a[i]);
 }
 mergesort(a,0,n-1);
 printf("Elements after sorting:\n");
 for(i=0;i<n;i++)
 {
  printf("%d\n",a[i]);
 }
}
void mergesort(int a[],int i,int j)
{
 int mid;
 if(i<j)
 {
  mid=(i+j)/2;
  mergesort(a,i,mid);
  mergesort(a,mid+1,j);
  merge(a,i,mid,mid+1,j);
 }
}
void merge(int a[],int i1,int j1,int i2,int j2)
{
 int temp[50];
 int i,j,k;
 i=i1;
 j=i2;
 k=0;
 while(i<=j1 && j<=j2)
 {
  if(a[i]<a[j])
  temp[k++]=a[i++];
  else
  temp[k++]=a[j++];
 }
 while(i<=j1)
 {
  temp[k++]=a[i++];
 }
 while(j<=j2)
 {
  temp[k++]=a[j++];
 }
 for(i=i1,j=0;i<=j2;i++,j++)
 {
  a[i]=temp[j];
 }
}

CS6512 - Internet Programming Lab

1. IMAGE MAPPING

india.html

<html>
<head>
<title>Image Mapping....</title>
</head>
<body>
<h1 style="text-align:center;font-family:Forte;color:violet">INDIA</h1>
<hr/>
<ul style="font-family:Comic Sans MS;size:3pt;color:darkblue" >
<li>The name India is derived from Indus, which is derived from the Old Persian word Hindu, from Sanskrit</li>
<li>India is the seventh-largest country by geographical area</li>
<li>The second-most populous country with over 1.2 billion people</li>
<li>The most populous democracy in the world</li>
<li>Consisting of 28 states and seven union territories</li>
<li>The name India is derived from Indus, which is derived from the Old Persian word Hindu, from Sanskrit</li>
</ul>
<p style="font-family:Calibri;size:4pt;color:red">
Click On The Hotspots To View More Information About That Particular Places...
</p>
<map name="indiamap">
<area shape="rect" coords="182,482,195,495" href="chennai.html" alt="Click here to get more details">
<area shape="rect" coords="151,159,162,167" href="delhi.html" alt="Click here to get more details">
<area shape="rect" coords="136,328,152,343" href="mumbai.html" alt="Click here to get more details">
<area shape="rect" coords="349,267,363,279" href="kolkatta.html" alt="Click here to get more details">
</map>
<img src="india.jpg" alt="Error on displaying Image" usemap="#indiamap" style="border:0">
</body>
</html>

chennai.html

<html>
<Title>Chennai....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">
Chennai, formerly known as Madras or Madarasapatinam,
is the capital city of the Indian state of Tamil Nadu...
</p>
<table>
<tr>
<td><img src="chennai.jpg" alt="Error on displaying Image"><br/>
    <span style="font-family:Cambria;color:blue;size:3pt">Parry's Corner</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Chennai being the fourth most populous metropolitan area and the fifth most populous city in India</li>
<li>It is also the world's 36th largest metropolitan area</li>
<li>Chennai's economy has a broad industrial base in the automobile, computer, technology, hardware manufacturing, and healthcare industries</li>
<li>The city is India's second largest exporter of software, information technology (IT) and information-technology-enabled services (ITES)</li>
<li>Chennai is a major centre for music, art and culture in India</li>
<li>The city is known for its classical dance shows and Hindu temples</li>
<li>Cricket is the most popular sport in Chennai</li>
<li>Chennai is the base for the large Tamil movie industry, known as Kollywood, home to most of the movie studios</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

delhi.html

<html>
<Title>Delhi....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">Delhi is the eighth largest
metropolis in the world by population with more than 12.25 million people...</p>
<table>
<tr>
<td><img src="delhi.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Lotus Temple</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Which also includes Noida, Greater Noida, Ghaziabad, Gurgaon and Faridabad along with other smaller nearby towns</li>
<li>Delhi has a maximum length of 51.9 km (32 mi) and the maximum width of 48.48 km (30 mi)</li>
<li>The annual mean temperature is 25 °C (77 °F)</li>
<li>The average annual rainfall is approximately 714 mm (28.1 inches)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

mumbai.html

<html>
<Title>Mumbai....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">
It is the most populous city in India, and the second most populous city in the world,
with a population of approximately 14 million...
</p>
<table>
<tr>
<td><img src="mumbai.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Gateway Of India</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Mumbai, formerly known as Bombay </li>
<li>Mumbai is the capital of the Indian state of Maharashtra</li>
<li>Mumbai is the commercial and entertainment capital of India</li>
<li>The average annual temperature is 27.2 °C (81.0 °F)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

kolkatta.html

<html>
<Title>Kolkata....</title>
<body>
<p style="font-family:Cambria;color:blue;size:3pt">Kolkata is the cultural capital of India
and the commercial capital of Eastern India...</p>
<table>
<tr>
<td><img src="kolkata.jpg" alt="Error on displaying Image"><br>
    <span style="font-family:Cambria;color:blue;size:3pt">Victoria Memorial</span></td>
<td>
<ul style="font-family:Cambria;color:blue;size:2pt">
<li>Kolkata, formerly known as Calcutta, is the capital of the Indian state of West Bengal</li>
<li>Before 1690 Kolkata, under direct rule of the Nawab of Bengal Siraj-Ud-Daulah</li>
<li>Kolkata is located in the eastern part India</li>
<li>The annual mean temperature is 26.8 °C (80.2 °F)</li>
</ul>
</td>
</tr>
</table>
<a style="font-family:Cambria;color:blue;size:2pt" href="india.html">Home</a>
</body>
</html>

2. WEB PAGE USING CASCADING STYLE SHEETS (CSS)

cssdemo.html

<html>
<head>
<title>NSCE</title>
<style type="text/css">
#tid1{background-color:gray;width:800px;height:200px;margin-left:15%;margin-right:15%}
#tid2{background-color:gray;width:800px;height:300px;margin-left:15%;margin-right:15%}
img{width:794px;height:200px}
</style>
<link rel="stylesheet" type="text/css" href="extStyle.css"/>
</head>
<body>
<h1 style="margin-left:18%;font-family:Courier New;color:blue">Narayanaguru College of Engineering</h1>
<hr/>
<table id="tid1">
<tr>
<td><img src="ngce.jpg" alt=""></td>
</tr>
</table>
<table id="tid2">
<tr>
<td class="cls1">
<h3 style="font-family:Lucida Sans Unicode;color:blue">About NGCE</h3>
<p>
Narayanaguru College of Engineering came into being
during 2002 - 2003 as a result of the aspirations of a large
number of well-wishers who wanted a global quality Engineering College
to impart value-based and discipline-oriented modern technical
education at affordable cost. The college was promoted by the
charitable trust, Narayanaguru International Institute of Science and Technology,
founded in 1999 by Dr.G.Sidhardhan. The college is located
near Manjaluumoodu, in Kanyakumari District.
</p>
</td>
<td class="cls1" style="vertical-align:top">
<h3 style="font-family:Lucida Sans Unicode;color:blue;text-align:center">Courses Offered</h3>
<div style="font-size:10pt;color:gold;font-family:Lucida Sans Unicode;text-align:justify">
<ul style="list-style:square">
<li>B.E - Automobile Engineering</li>
<li>B.E - Civil Engineering</li>
<li>B.E - Computer Science & Engineering</li>
<li>B.E - Electronics & Communication Engineering</li>
<li>B.E - Electrical & Electronics Engineering</li>
<li>B.E - Mechanical Engineering</li>
<li>M.E-Computer Science and Engineering</li>
<li>M.E-Applied Electronics</li>
<li>M.E-Structural Engineering</li>
<li>MBA-Master of Business Administration</li>
<li>MCA-Master of Computer Application</li>
</ul>
</div>
</td>
</tr>
</table>
</body>
</html>

extStyle.css

body{background-color:black}
.cls1{width:325px;height:300px}
p{font-family:Lucida Sans Unicode;color:silver;font-size:12pt;text-align:justify}

3. IMPLEMENTATION OF FTP

ftpclient.java

import java.net.*;
import java.lang.*;
import java.io.*;
public class ftpclient
{
public static void main(String args[])
{
try
{
FileInputStream f=new FileInputStream("clientfile.txt");
int si=f.available();
Socket s=new Socket("localhost",3000);
PrintStream p=new PrintStream(s.getOutputStream());
for(int i=0;i<si;i++)
{
char r=(char)f.read();
p.print(r);
System.out.print(r);
}
s.close();
System.out.println("\n\nThe File Transferred to server Successfully.............\n");
}
catch(Exception e)
{
System.out.println(e);
}
}
}

ftpserver.java

import java.net.*;
import java.lang.*;
import java.io.*;
public class ftpserver
{
public static void main(String args[])
{
try
{
File f=new File("serverfile.txt");
FileWriter f1=new FileWriter(f);
BufferedWriter bw=new BufferedWriter(f1);
ServerSocket ss=new ServerSocket(3000);
Socket s=ss.accept();
BufferedReader br=new BufferedReader(new InputStreamReader(s.getInputStream()));
String st=null;
while((st=br.readLine())!=null)
{
System.out.println(st);
bw.write(st);
bw.newLine();
}
br.close();
bw.close();
f1.close();
System.out.println("\n\nThe File Received from the client Successfully.............\n");
}
catch(Exception e)
{
System.out.println(e);
}
}
}

4. SIMPLE CHAT APPLICATION

client.java

import java.io.*;
import java.net.*;
class client
{
public static void main(String args[])throws IOException
{
int cport=789,sport=790;
byte b[]=new byte[1024];
DatagramSocket soc=new DatagramSocket(cport);
DatagramPacket dp=new DatagramPacket(b,b.length);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
System.out.println("Client is Running... Type 'STOP' to Quit");
while(true)
{
String str=new String(br.readLine());
b=str.getBytes();
if(str.equals("STOP"))
{
System.out.println("Terminated...");
soc.send(new DatagramPacket(b,str.length(),ia,sport));
break;
}
soc.send(new DatagramPacket(b,str.length(),ia,sport));
soc.receive(dp);
String str2=new String(dp.getData(),0,dp.getLength());
System.out.println("Server:"+str2);
}
}
}

server.java

import java.io.*;
import java.net.*;
class server
{
public static void main(String args[])throws IOException
{
int cport=789,sport=790;
byte b[]=new byte[1024];
DatagramSocket ss=new DatagramSocket(sport);
DatagramPacket dp=new DatagramPacket(b,b.length);
BufferedReader dis=new BufferedReader(new InputStreamReader(System.in));
InetAddress ia=InetAddress.getLocalHost();
System.out.println("Server is Running...");
while(true)
{
ss.receive(dp);
String str=new String(dp.getData(),0,dp.getLength());
if(str.equals("STOP"))
{
System.out.println("Terminated...");
break;
}
System.out.println("Client: "+str);
String str1=new String(dis.readLine());
b=str1.getBytes();
ss.send(new DatagramPacket(b,str1.length(),ia,cport));
}
}
}

5. WEB APPLICATION USING XML AND JSP

user.xml

<?xml version="1.0" encoding="utf-8"?>
<userInfo>
<user>
<UID>001</UID>
<Name>AAA</Name>
<Regno>963714104001</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>002</UID>
<Name>BBB</Name>
<Regno>963714104002</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>003</UID>
<Name>CCC</Name>
<Regno>963714104003</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>004</UID>
<Name>DDD</Name>
<Regno>963714104004</Regno>
<Branch>CSE</Branch>
</user>
<user>
<UID>005</UID>
<Name>EEE</Name>
<Regno>963714104005</Regno>
<Branch>CSE</Branch>
</user>
</userInfo>

user.html

<html>
<head>
<title>Student Details</title>
</head>
<body>
<h3 align="center">USER DETAILS</h3>
<hr color="blue">
<form name="frm1" method="GET" action="http://localhost:8080/Ex5/user.jsp">
<table border="1" align="center">
<tr>
<td>Enter User ID:</td>
<td><input type="text" name="uid"></td>
<td><input type="submit" value="SUBMIT"></td>
</tr>
</table>
</form>
</body>
</html>

user.jsp

<%@page contentType="text/html;charset=utf-8" language="java" import="javax.xml.parsers.*,org.w3c.dom.*"%>
<%
try
{
String user=request.getParameter("uid");
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db=dbf.newDocumentBuilder();
Document doc=db.parse("http://localhost:8080/Ex5/user.xml");
NodeList id=doc.getElementsByTagName("UID");
NodeList n=doc.getElementsByTagName("Name");
NodeList r=doc.getElementsByTagName("Regno");
NodeList b=doc.getElementsByTagName("Branch");
%>
<h3 align="center">User Details</h3>
<hr color="blue">
<%
for(int i=0;i<r.getLength();i++)
{
if(id.item(i).getFirstChild().getNodeValue().equals(user))
{
%>
<table border="1" align="center">
<tr><td>Name</td><td><%=n.item(i).getFirstChild().getNodeValue()%></td></tr>
<tr><td>Register Number</td><td><%=r.item(i).getFirstChild().getNodeValue()%></td></tr>
<tr><td>Branch</td><td><%=b.item(i).getFirstChild().getNodeValue()%></td></tr>
</table>
<%
}
}
}
catch(Exception e)
{
out.println(e);
}
%>
<a href="user.html">Back</a>

6. INVOKING SERVLETS FROM HTML FORM

client.html

<html>
<head>
<title>Invoking Servlet From HTML</title>
</head>
<body>
<form name="form1" method="post" action="http://localhost:8080/Ex6/server">
<fieldset>
<legend>Registration</legend>
Enter E-mail&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:
<input type="text" name="LoginID" size="25"/><br/><br/>
Enter Password:
<input type="password" name="Password" size="25">
<input type="submit" Value="SUBMIT">
</fieldset>
</form>
</body>
</html>

server.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class server extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
pw.print("<h3>Registration Successfull...</h3>");
Enumeration e=req.getParameterNames();
while(e.hasMoreElements())
{
String str1=(String)e.nextElement();
String str2=req.getParameter(str1);
pw.print(str1+"="+str2+"<br/>");
}
pw.close();
}
}

7. INVOKING SERVLETS FROM APPLETS

AppletClient.java

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class AppletClient extends Applet implements ActionListener
{
public void init()
{
Label la=new Label("INVOKING SERVLET FROM APPLET");
la.setFont(new Font("Courier",Font.BOLD,15));
la.setForeground(Color.blue);
add(la);
Button b1=new Button("Click Here To Display Date Information From Server");
b1.setBackground(Color.black);
b1.setForeground(Color.white);
add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
AppletContext ac=getAppletContext();
URL url = new URL("http://localhost:8080/Ex7/MyServer");
ac.showDocument(url);
}
catch(Exception e)
{
System.out.println(e);
}
}
}

AppletClient.html

<html>
<head>
<title>Invoking Servlets From Applet</title>
</head>
<body>
<applet code="AppletClient.class" width="400" height="200">
</applet>
</body>
</html>

MyServer.java

import java.io.*;
import java.util.*;
import javax.servlet.*;
public class MyServer extends GenericServlet
{
public void service(ServletRequest req,ServletResponse res)throws ServletException,IOException
{
PrintWriter pw=res.getWriter();
Date d=new Date();
pw.println("<html><body><h2>Srever Response</h2>");
pw.println("<h3>Current Date and Time From Server:</h3>");
pw.println("<b>"+d+"</b></body></html>");
}
}

8. ONLINE EXAMINATION USING SERVLETS

examDB.accdb (Design)


examDB.accdb (Table)


ExamClient.html

<html>
<head>
<title>Online Exam Client</title>
</head>
<body>
<h2>ONLINE EXAMINATION</h2>
<h3>Answer the following questions (5 marks for each correct answer)</h3>
<hr/>
<form name="examForm" method="post" action="http://localhost:8080/Ex8/ExamServer">
1.Who is called as the father of computer?<br/>
<input type="radio" name="ans1" value="Sachin">Sachin
<input type="radio" name="ans1" value="Stuart">Stuart
<input type="radio" name="ans1" value="Charles Babbage">Charles Babbage
<input type="radio" name="ans1" value="Napier">Napier
<br/><br/>
2.C++ was developed by?<br/>
<input type="radio" name="ans2" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans2" value="None">None
<input type="radio" name="ans2" value="David Ritchie">David Ritchie
<input type="radio" name="ans2" value="John">John
<br/><br/>
3.C was developed by?<br/>
<input type="radio" name="ans3" value="Dennis Ritchie">Dennis Ritchie
<input type="radio" name="ans3" value="Stroustrup">Stroustrup
<input type="radio" name="ans3" value="David Ritchie">David Ritchie
<input type="radio" name="ans3" value="Charles Babbage">Charles Babbage
<br/><br/>
<input type="submit" value="Check Your Result"/>
</form>
</body>
</html>

ExamServer.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class ExamServer extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String str1=req.getParameter("ans1");
String str2=req.getParameter("ans2");
String str3=req.getParameter("ans3");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\examDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM examTab");
int mark=0,i=1;
while(rs.next())
{
if(i==1)
{
String dbans1=rs.getString(1);
if(str1.equals(dbans1))
{
mark=mark+5;
}
}
if(i==2)
{
String dbans2=rs.getString(1);
if(str2.equals(dbans2))
{
mark=mark+5;
}
}
if(i==3)
{
String dbans3=rs.getString(1);
if(str3.equals(dbans3))
{
mark=mark+5;
}
}
i++;
}
if(mark>=10)
{
pw.print("<h4>Your Mark Is : "+mark+"</h4>");
pw.print("<h3>Congratulations....! You are eligible for the next round...</h3>");
}
else
{
pw.print("<h4>Your Mark is : "+mark+"</h4>");
pw.print("<h3>Sorry....!! You are not eligible for the next round...</h3>");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

9. DISPLAYING STUDENT'S MARK DETAILS USING SERVLETS

markDB.accdb (Design)


markDB.accdb (Table)



mark.html

<html>
<head>
<title>Three Tier Application</title>
</head>
<body>
<h2>EXAMINATION RESULT</h2><hr/>
<form name="f1" method="get" action="http://localhost:8080/Ex9/mark">
Enter Your Reg.No:
<input type="text" name="regno"/><br/><br/>
<input type="submit" value="SUBMIT"/>
</form>
</body>
</html>

mark.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class mark extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String str=req.getParameter("regno");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\markDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT*FROM markTab WHERE rno="+str);
while(rs.next())
{
pw.print("Register No:"+rs.getObject(1)+"<br/>");
pw.print("Name:"+rs.getObject(2));
pw.print("<table border=1>");
pw.print("<th>SUBJECT</th><th>MARK</th>");
pw.print("<tr><td>Internet Programming</td><td>"+rs.getObject(3)+"</td></tr>");
pw.print("<tr><td>Object Oriented Analysis and Design</td><td>"+rs.getObject(4)+"</td></tr>");
pw.print("<tr><td>Computer Graphics</td><td>"+rs.getObject(5)+"</td></tr>");
pw.print("<tr><td>Theory of Computation</td><td>"+rs.getObject(6)+"</td></tr>");
pw.print("<tr><td>Discrete Mathematics</td><td>"+rs.getObject(7)+"</td></tr></table>");
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}

10. AJAX AUTO COMPLETE

stateDB.accdb (Design)


stateDB.accdb (Table)



AutoComplete.html

<html>
<head>
<title>AJAX Demo</title>
<script type="text/javascript">
var req;
function showData(val)
{
var url="http://localhost:8080/Ex10/AutoComplete";
if(val=="")
{
document.getElementById("mydiv").innerHTML="";
return;
}
if(window.ActiveXObject)
{
req=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest)
{
req=new XMLHttpRequest();
}
req.onreadystatechange=display;
req.open("POST",url,true);
req.setRequestHeader("Content-type","application/x-www-form-urlencoded");
req.send("state="+val);
}
function display()
{
if(req.readyState==4||req.readyState=="complete")
{
document.getElementById("mydiv").innerHTML=req.responseText;
}
}
</script>
</head>
<body>
Enter Your State:<br/>
<input type="text" name="state" onkeyup="showData(this.value)"><br/>
<div id="mydiv"></div>
</body>
</html>

AutoComplete.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
public class AutoComplete extends HttpServlet
{
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String s=req.getParameter("state");
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\SreekandanK\\Desktop\\IPLab-Netbeans\\stateDB.accdb");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select*from stateTab where state like '"+s+"%'");
while(rs.next())
{
pw.println("<div>"+rs.getObject(1)+"</div>");
}
con.close();
stmt.close();
}
catch(Exception e){}
}
}

11. SESSION TRACKING USING HIDDEN FORM FIELDS

home.html

<html>
<head>
<title>Session Tracking - Hidden Form Fields</title>
</head>
<body>
<form method="get" action="http://localhost:8080/Ex11/server1">
<table border="1">
<tr>
<td>Name:</td><td><input type="text" name="userName"/></td>
<td><input type="submit" value="GO"/></td>
</tr>
</table>
</form>
</body>
</html>

server1.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class server1 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String n=req.getParameter("userName");
pw.print("Welcome: "+n);
pw.print("<form action='http://localhost:8080/Ex11/server2'>");
pw.print("<input type='hidden' name='uname' value="+n+">");
pw.print("<input type='submit' value='NEXT'>");
pw.print("</form>");
pw.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

server2.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class server2 extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
{
try
{
res.setContentType("text/html");
PrintWriter pw=res.getWriter();
String n=req.getParameter("uname");
pw.print("Hello, "+n);
pw.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

12. SESSION TRACKING TO DISPLAY HIT COUNT

HitCount.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class HitCount extends HttpServlet
{
private int visit=0;
public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
HttpSession session=req.getSession(true);
res.setContentType("text/html");
PrintWriter out=res.getWriter();
visit++;
String heading;
if(session.isNew())
{
heading="Welcome, New User";
}
else
{
heading="Welcome Back";
}
out.println("<h2>"+heading+"</h2>");
out.println("<h3>Information on Your Session:</h3>");
out.println("<table border=1><tr><th>Info Type<th>Value</th>");
out.println("<tr><td>Session ID</td><td>"+session.getId()+"</td></tr>");
out.println("<tr><td>Creation Time</td><td>"+new Date(session.getCreationTime())+"</td></tr>");
out.println("<tr><td>Time of Last Access</td><td>"+new Date(session.getLastAccessedTime())+"</td></tr>");
out.println("<tr><td>Number of Visits</td><td>"+visit+"</td></tr>");
out.println("</table>");
}
}

Popular Posts

About Author

Marthandam, Tamilnadu, India