Pages

Wednesday, September 11, 2013

Mcsl-054(Advanced Internet Technologies)

Mcsl-054

PART-I: MCS-051 (Advanced Internet Technologies)


QUESTION-1:  Develop a web page using Servlet which ask for your name and address  and print a message “ Welcome! Mr./Miss.  Your Name on this web page” and show the current date and time on the top of web page.                                                                                                              
Soltion:

Imporr javax.servlet.*;
Imporr javax.servlet.http.*;
Imporr java.io.*;
Imporr java.utill.Date;

Public clasas HelloServlet extends HttpServlet
{
Public void (HttpServletRequest, request, HttpServlet response)
                        Throws IoException, ServletException 
{
Response.setContentType(“Text/html”);
PrintWriter  out = response.getWriter();
Out.println (“<Htmt>”);
Out.println (“<Body>”);
Out.println (“Enter your name<input type=”text”  name=”a”>”);
Out.println (“Address <input type =”text” name =”b>”);
String n = request.getParameter (“a”);
Out.println (“Welcome! Mr./Miss” +a);
Out.println (“new.java.util.Date( ));
}
}


QUESTION-2 : Write a JSP Program, which displays a web page containing two web links one for your profiling and other for the schedule of  theory of practical classes of your Batch. When one click on link for getting your profile it goes to a JSP page which display your personal profile and by clicking on link for classes schedule another JSP page will open to show the schedule

Solution:

Menu.Jsp

<html>
<body>
<form action =”profile.jsp” method = “post”>
<input type = “submit” value=”PROFILE”>
</form>
<form action=”schedule.jsp method=”post”>
<input type=submit” value=”SCHEDULE”>
</form>
</body>
</html>
</html>

 Profile.jsp

<html>
<body>
<h1> MY PROFILE </h1>
NAME            VINITA AGARWAL
ADDRESS     A-16/F NEW DELHI
SCHOOL        MCS.SBM., NEW DELHI
UNIVERSITY           I.G.N.O.U
QULIFICATION       B.C.A, Pursuing M.C.A
Skills                           C, C++, JAVA
Ph. No.                        9811836816

</Body>
</html>

Schedule. Jsp

<html>
<body>
<h1> Schedulen OF MCA(5) THEORY <h1>
<b> MCS-051 </B>
Monday
Tuesday
Saturday
<b>  MCS-052 </b>
Sunday
<b>  MCS-053 </b>
Saturday
Sunday
</body>
<html>



QUESTION-3: Write a program using JDBC and JSP to display the computer books available in your Study Centres Library. Provide suitable options for issue/return of the books and searching and pupation in the library database.     

Solution:

SO.jsp

<html>
<body>
<form action = “Book.jsp”  method = “post”>
<input type =”submit”   value = “BookInfo”>
</form>
<form action = “Issue.jsp”  method = “post”>
<input type =”submit”   value = “Issue”>
</form>
<form action = “Search.jsp”  method = “post”>
<input type =”submit”   value = “Search”>
</form>
<form action = “Retun.jsp”    method = “post”>
<input type =”submit”   value = “Return”>
</form>
</body>
</html>

Book.jsp

 <%  @  language=”java”  import= “java.sql.*”, “java.io>
<html>
<body>
<%
Class.forName (“Com.mywqyl.jdbc.Driver”);
Connection   con=DriverManager.getConection(“jdbc : mysql : // localhost / institute”, “root”, “1234”);

Statement     st = con.createStatement( );
ResultSet    rs = st.executeQuery(“Select * from Liabrary where subject =”computer”);

Int    i= 0;
While (rs.next(i) = = True)
{
Out.println(rs.getString (i)”);
}
%>
</body>
</html>
Issue.jsp

<html>
<body>
<form action =”issued.jsp”    method = “post”>
ID NO.  <input type = “text”   name=”b”>
<%
<input type = “submit”   value= “IssueBook”>
</form>
</body>
</html>


QUESTION-4. Create an XML document for student’s record at your Study Centre.

Solution:

<?xml version=1.0 ?>
<student Records>
<student Record>
<Name> VINITA AGGARWAL</Name>
<PROGRAMME> MCA </PROGRAMME>
<E-No> 063501077</E-No>
<Address> g-14/B, Kiran Graden, uttam Naga r</Address>
<ph-no> 9811836856 </Ph-no>
<Student Record>
<Name> Shweta Chopra </Name>
<PROGRAMME> MCA </PROGRAMME>
<E-NO> 063502656 </E-NO>
<ADDRE SS> A-17/F,u.n </ADDRESS>
<ph.no> 9958621533 </ph.no>
</student record>
</student records>

Issued.jsp

<% @ language=”java” import=”java.co.x” %>
<html.
<body>
<% string b1 = response.getParameter(“a”);
Class.for Name(“Com.mysql.jdbc.Driver”);
Connection con = drivermanager.getconnetion(“jdbc:mysql://localhost”institute”, “root”, “1234”>
Statement st= con.createstatement();
Result rs= st.execute update (“update library set status=”issued” whereBook_title=””
%>

Search.jsp

<html>
<body>
<form action=”searchavailable” method=post”>
Enter Book name<input type=”text” name=”a”>
Search For availability
<input type=”submit” value”search for availability”>
</form>
</body>
</html>

Searchavailable.jsp

<% @ language=”java” import=”java.io.x”, “java.sql.x”%>
<html>
<body>
<%
String = response.getParameter(“a”);
Class.forName(“com.mysql.jdbs.Driver”);
Connection con=DriverManager.getConnection(“jdbc”.mysql://localhost/institute”, “root”, “1234”);
Statement sr-con.createstatement ();
Resukt rs=st.executeQuery (“select status from Library where Book_title=”+a+”’”);
String out= rs.getString(1);
Out.printer(n(“status=” +out+);
%>
</body>
</html>




HomeWork
-------------

Question 1:   Write a program using Servlet/JSP that accepts the account number of a bank customer as input. The program should print the details of the account. Make necessary assumptions whereever required.  


Question 2:   Write a JSP Program, which displays a web page containing two web links one for showing schedule of counselling sessions at a Study Centre and other for FAQs on Programme on offer by the university. When one click on link Study Centre it goes to a page which show the counselling schedule for MCA students. Clicking on link for FAQs on Programme on Offer, another JSP page open, which  consists of some FAQ related to different programme offered in the University. 


Question 3:  Write a program using JSP and JDBC to provide details of MCA/BCA/CIT students at a IGNOU study centres. Also the program should enable any student to change his/her address. This program should provide the practical attendance detail of students in different semesters of MCA/BCA/CIT. 


Question 4:   Create an XML document for keeping students record in a department of a University.

Power program in LISP

[1]Write LISP program and define function named power that takes two numeric arguments, n and m, that computes nth power of m (i.e., m^n).

Answer

Without Recursion
-------------------
(defun  pow( )
(setf  m(read))
(setf  n(read))
(setf  c 1)
(dotimes  (i n)

   (setf  c ( * c m))
)



Expln:

Every lisp program will start a symbol '(' .
1) Define a function named 'pow'
2) Read 'm' variable
ie; scanf  in C
3) Read 'n' variable
4) Initialise  c=1
5) For loop 
ie;  in C, for(i=0;i<n;i++)

'dotimes' only for  increment operations.
For decrementing......use  another method for 'For-loop'..

(loop for ...) refer this 

6) Set  c=c * m
In LISP,

We will use  prefix notation.
ie; why we using 

(*  c m )

Saturday, September 7, 2013

Write LISP & C Program for bubble sort ....See the difference ????

; Program by Arun Anoop M

; Asst.Professor,CSE.


(defun  bubble nil

(format  t   "Enter your number n :")

(setf   n(read))

(setf  i 0)


(format  t  "Enter array elements : ")

(setf  a(make-array  n))

(dotimes  (i  n)

   (setf  (aref  a  i) (read)
)

(print  a)

  (sort1  a  n)
  (print  "Sorted vector is :")
  (print  a)

(defun  sort1 (a  n)

  (setf   j(i+1))

  (dotimes  (i  n )

     (dotimes  (j  n )

(cond (( < (aref  a  i) (aref  a  j))

     (setf   temp (aref  a  i))

     (setf  (aref  a  i) (aref  a j))

     (setf  (aref  a  j) (temp))
)

)

)

)


--------------------------------------------------------------------------------------------


#include<stdio.h>

void main()
{
       int i,j,n,temp;
       int A[50];
       clrscr();
       printf("Enter the no. of element::");
       scanf("%d",&n);

       printf("Enter elements in array\n");

       for(i=0;i<n;i++)
       {
              printf("element %d is : ",i+1);
              scanf("%d",&A[i]);
       }

       printf("\nElements enter by you is::\n");
       for(i=0;i<n;i++)
       {
              printf("%d\t",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("\nelements sorted in asending order\n");
       for(i=0;i<n;i++)
       {
              printf("%d\t",A[i]);
       }

       getch();

}

Thursday, September 5, 2013

PC to PC serial communication-PC1

/*Program : PC to PC serial communication-PC1*/
/*Programmed By : Lubin*/
#define COM_BASE 0x3f8
#define DFR COM_BASE+3
#define LDLR COM_BASE
#define HDLR COM_BASE+1
#define SSR COM_BASE+5
#include<asm/io.h>
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
static inline unsigned char recv_char()
{
while(!(inb(SSR) & 1));
return inb(COM_BASE);
}
void uart_init()
{
iopl(3);
outb(0x83,DFR);
outb(0x18,LDLR);
outb(0,HDLR);
outb(0x03,DFR);
}
int main(int argc,char *argv[])
{
int count,fd,i=0;
unsigned char ch,fname[30];
uart_init();
if(argc>1)
fd=open(argv[1],O_CREAT | O_WRONLY);
else
{
printf("Enter the output file\n");
scanf("%s",fname);
fd=open(fname,O_CREAT | O_WRONLY);
}
printf("Receiving....\n");
do
{
ch=recv_char();
if((char)ch!=EOF)
{
count=write(fd,&ch,1);
i++;
}
}while((char)ch!=EOF);
close(fd);
printf("Received %d bytes\n",i);
return 0;
}

SLIDING WINDOW - SERVER & Client

/* SLIDING WINDOW - SERVER
* PROGRAMMED BY: LUBIN N*/
#include<stdio.h>
#include<stdlib.h>
#include<netinet/in.h>
#include<fcntl.h>
#include<string.h>
main()
{
struct sockaddr_in server;
int d,e,new;
char c;
d=socket(AF_INET,SOCK_STREAM,0);
server.sin_port=htons(2005);
server.sin_family=AF_INET;
server.sin_addr.s_addr=INADDR_ANY;
e=bind(d,(struct sockaddr *)&server,sizeof(server));
if(e==0)
printf("\nBinding.....\n");
listen(d,1);
int n=sizeof(struct sockaddr_in);
new=accept(d,(struct sockaddr *)&server,&n);
while(1)
{
read(new,&c,1);
if(c=='d')
printf("Received....\n");
c='a';
write(new,&c,1);
printf("\n\n\n\t\t\tAcknowledged...........\n");
}
}




/* SLIDING WINDOW - CLIENT
* PROGRAMMED BY: LUBIN */
#include<stdio.h>
#include<pthread.h>
#include<stdlib.h>
#include<sys/socket.h>
#include<unistd.h>
#include<netinet/in.h>
#include<fcntl.h>
#define window 10
int up=0,low=0,c;
void *senddata()
{
char ch='d';
while(1)
{
up++;
while(up-low>window)
{
printf("\nCompetition......Sender waiting...\n");
sleep(1);
}
printf("\t\tSending data....%d\n",up-1);
write(c,&ch,1);
}
}
void *receivedata()
{
char ch;
while(1)
{
read(c,&ch,1);
if(ch=='a')
{
printf("\n\nACK recieved for data %d\n",low);
low++;
sleep(2);
}
}
}
main()
{
pthread_t s,r;
struct sockaddr_in server;
c=socket(AF_INET,SOCK_STREAM,0);
server.sin_family=AF_INET;
server.sin_port=htons(2005);
server.sin_addr.s_addr=inet_addr("127.0.0.1");
connect(c,(struct sockaddr*)&server,sizeof(server));
pthread_create(&s,0,senddata,0);
pthread_create(&r,0,receivedata,0);
while(1);
}



//www.edutalks.org



SMTP TCP Client & Server

/*
 * SMTP USING TCP : Server Program
 * Programmed by : Lubin N
 */
#include<stdio.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<string.h>
#define PORT 4100
main()
{
struct sockaddr_in servaddr,cliaddr;
int sock1,sock2,len,l,fd,lsize,i,ch;
char fname[15],buff[500],sendname[15];
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(PORT);
servaddr.sin_addr.s_addr=INADDR_ANY;
sock1=socket(AF_INET,SOCK_STREAM,0);
bind(sock1,(struct sockaddr *)&servaddr,sizeof(servaddr));
printf("bind\n");
listen(sock1,4);
sock2=accept(sock1,(struct sockaddr *)&cliaddr,&len);
printf("accept\n");
printf("from:");
l=read(sock2,sendname,15);
puts(sendname);
for(i=0;i<l;i++)
fname[i]=sendname[i];
fd=open(fname,O_RDWR | O_CREAT,0777);
len=read(sock2,buff,500);
printf("no of characters read %d\n",len);
write(fd,buff,len);
printf("%s\n",buff);
close(sock1);
close(sock2);
}



/*
 * SMTP USING TCP : Client Program
 * Programmed by : Lubin N
 */
#include<stdio.h>
#include<arpa/inet.h>
#include<fcntl.h>
#include<string.h>
#define PORT 4100
main()
{
int sock,len;
char buff[500],sendname[15],recvname[15];
struct sockaddr_in servaddr,cliaddr;
servaddr.sin_family=AF_INET;
servaddr.sin_port=htons(PORT);
servaddr.sin_addr.s_addr=INADDR_ANY;
sock=socket(AF_INET,SOCK_STREAM,0);
connect(sock,(struct sockaddr *)&servaddr,sizeof(servaddr));
printf("Enter the name of sender\n");
gets(sendname);
write(sock,sendname,15);
printf("Enter the name of receiver\n");
gets(recvname);
printf("Enter the data\n");
gets(buff);
len=strlen(buff);
write(sock,buff,len);
close(sock);
}

SMTP UDP Server & Client

/* SMTP USING UDP - SERVER

* PROGRAMMED BY: LUBIN N


Programs in NETWORKS By Lubin, GEC Palakkad */


// www.edutalks.org


#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<fcntl.h>
#include<arpa/inet.h>
#define SERV_UDP_PORT 4100
#define MAXMESG 2048
dg_echo(int sockfd, struct sockaddr *pcli_addr, int maxclilen)
{
int n,m,clilen,fid,lsize,i;
char msg[MAXMESG],filename[15],fname[15],buf[512];
printf("______________serv\n");
printf("accept\n");
printf("from: ");
m = recvfrom(sockfd, filename,m, 0 ,pcli_addr, &clilen);
// puts(filename);
for(i=0;i<m;i++)
{
fname[i]=filename[i];
printf("%c",fname[i]);
}
fid=open(fname,O_RDWR | O_CREAT,0777);
n = recvfrom(sockfd, buf,n, 0 ,pcli_addr, &clilen);
printf("\n msg recvd %s\n",buf);
write(fid,buf,n);
close(fid);
}
main(int argc, char *argv[])
{
int sockfd;
char choice;
char buf[200],filename[15],fname[15];
struct sockaddr_in serv_addr,cli_addr;
if((sockfd=socket(AF_INET,SOCK_DGRAM,0))<0)
printf("serveer: caan't open datagram socket");
bzero((char *)&serv_addr,sizeof(serv_addr));
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);
serv_addr.sin_port=htons(SERV_UDP_PORT);
if(bind(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr))<0)
printf("server: can't bind local address\n");
printf("bind on serv\n");
dg_echo(sockfd,(struct sockaddr *) &cli_addr, sizeof(serv_addr));
}






/* SMTP USING UDP - CLIENT
* PROGRAMMED BY: LUBIN N*/
#include<stdio.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<fcntl.h>
#include<arpa/inet.h>
#define SERV_UDP_PORT 4100
#define MAXLINE 512
dg_cli(FILE *fp,int sockfd,struct sockaddr *pserv_addr,int servlen)
{
int n,m,fd;
char sendline[MAXLINE],recvline[MAXLINE+1],filename[15],fname[15],buf
[512],ch;
printf("___________\n");
printf("Enter the name of sender\n");
gets(sendline);
m=strlen(sendline);
if(sendto(sockfd,sendline,m,0,pserv_addr,servlen)!=m)
printf("error\n");
printf("Enter the name of receiver\n");
gets(recvline);
printf("Enter the message : ");
gets(sendline);
n=strlen(sendline);
if(sendto(sockfd,sendline,n,0,pserv_addr,servlen)!=n)
printf("error\n");
}
main(int argc, char *argv[])
{
int sockfd;
struct sockaddr_in cli_addr,serv_addr;
bzero((char *)&serv_addr,sizeof(serv_addr));
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr=(INADDR_ANY);
serv_addr.sin_port=htons(SERV_UDP_PORT);
if((sockfd=socket(AF_INET,SOCK_DGRAM,0))<0)
printf("error\n");
bzero((char *)&cli_addr,sizeof(cli_addr));
cli_addr.sin_addr.s_addr=htonl(INADDR_ANY);
cli_addr.sin_family=AF_INET;
cli_addr.sin_port=htons(0);
if(bind(sockfd,(struct sockaddr*)&cli_addr,sizeof(cli_addr))<0)
printf("error\n");
printf("bind on client\n");
dg_cli(stdin, sockfd, (struct sockaddr *) &serv_addr, sizeof
(serv_addr));
close(sockfd);
exit(0);
}