The document appears to be a student lab record for an Advanced Java Programming course. It includes details of various Java programming assignments completed by the student over the 2009-2012 academic years related to TCP/IP communication, web applications, web services, and Java database connectivity. The assignments involve writing and executing Java code to demonstrate concepts like client-server programming, JSP-Servlet communication, RMI, and JDBC.
The document appears to be a student lab record for an Advanced Java Programming course. It includes details of various Java programming assignments completed by the student over the 2009-2012 academic years related to TCP/IP communication, web applications, web services, and Java database connectivity. The assignments involve writing and executing Java code to demonstrate concepts like client-server programming, JSP-Servlet communication, RMI, and JDBC.
The document appears to be a student lab record for an Advanced Java Programming course. It includes details of various Java programming assignments completed by the student over the 2009-2012 academic years related to TCP/IP communication, web applications, web services, and Java database connectivity. The assignments involve writing and executing Java code to demonstrate concepts like client-server programming, JSP-Servlet communication, RMI, and JDBC.
The document appears to be a student lab record for an Advanced Java Programming course. It includes details of various Java programming assignments completed by the student over the 2009-2012 academic years related to TCP/IP communication, web applications, web services, and Java database connectivity. The assignments involve writing and executing Java code to demonstrate concepts like client-server programming, JSP-Servlet communication, RMI, and JDBC.
ADVANCE JAVA PROGRAMMING LAB RECORD NOTE 2009-2012
NAME : ___________________________________________
REGISTER NO : ___________________________________________
SUB CODE : 08PBCA61
SCHOOL OF COMPUTING SCIENCES
DEPARTMENT OF INFORMATION TECHNOLOGY
CERTIFICATE This is to certify that the bonafide record of practical work done by___________________________________ Register No.____________________ Of III BCA, VELS University, Pallavaram, Chennai, during the year of 2011-2012.
STAFF-IN-CHARGE HEAD OF THE DEPARTMENT
Submitted for III BCA Practical Examination held on ___________________, in the Department of IT at VELS University, Pallavaram, Chennai - 117.
INTERNAL EXAMINER EXTERNAL EXAMINER 1
INDEX
S.NO
DATE
CONTENTS
PAGE NO
SIGNATURE
1.
10.1.2012
TCP/IP Server-Client Communication
2
2.
19.1.2012
HTML to Servlet Communication
6
3.
02.02.2012
Creating Web Services with RMI
10
4.
07.02.2012
Performing Java Data Base Connectivity
15
5.
16.02.2012
JSP to JDBC Communication.
18
6.
23.02.2012
Designing Online Application with JSP
24
7.
01.03.2012
Creating JSP program using Java Bean
28
8.
15.03.2012
E-Mail Application using JSP
31
9.
20.03.2012
Performing Session Management Using JSP
35
2
1. TCP/IP Client Server Communication. Date: 10.01.2012 Aim: To execute a program on TCP/IP Client Server Communication Procedure:
Step 1: Open the Notepad. Step 2: Type the program and save the TCPServer.java. Step 3: Open the cmd prompt and compile the program then Run the program. Step 4: Open the Notepad.
Step 5: Type the program and save the TCPClient.java.
Step 6: Open the cmd prompt and compile the program then Run the program
Step 7: Enter the String in the Client Program
Step 8: Got Output from the Server for Lowercase Convert into uppercase the output displayed on Client Program.
TCP Client: import java.io.*; import java.net.*; class TCPClient { public static void main(String argv[]) throws Exception { String sentence; String modifiedSentence; BufferedReader inFromUser=new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket=new Socket("localhost",5000); System.out.println("enter the string"); DataOutputStream outToServer=new DataOutputStream(clientSocket.getOutputStream()); BufferedReader inFromServer=new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence=inFromUser.readLine(); outToServer.writeBytes(sentence + '\n'); modifiedSentence=inFromServer.readLine(); System.out.println("FROM SERVER TO UPPERCASE:"+modifiedSentence); clientSocket.close(); } }
5
OUTPUT
Result:
Thus the program has been successfully executed and output is verified.
6
2. HTMLTO SERVLET Date: 19.01.2012 Aim:
To design a web application with JSP to Servlet Communication
Procedure:
Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: Open the saved application and write the coding in JSP Page Step 3: Create new servlet page in same web application and write coding Step 4: Save all and run the application
Step 5: Enter the details in JSP page and output will be displayed in servlet page after execution
Thus the program has been successfully executed and output is verified.
10
3. CREATING WEB SERVICES WITH RMI Date: 02.02.2012 Aim: To create web services using concept of RMI.
Procedure:
Step 1: Select ->Notepad ->create new document Step 2: Write a code and import the Interface class Step 3: write a code for client side as well as server side Step 4: Save the entire file in one folder as java file Step 5: set path of JDK in command prompt and compile the program Step 6: Run the program. Step 7: Stop the execution. . 11
Calculator Interface (Calculator.java)
public interface Calculator extends java.rmi.Remote { public long add(long a,long b)throws java.rmi.RemoteException; public long sub(long a,long b)throws java.rmi.RemoteException; public long mul(long a,long b)throws java.rmi.RemoteException; public long div(long a,long b)throws java.rmi.RemoteException; }
Calculator Implementation (CalculatorImpl.java)
public class CalculatorImpl extends java.rmi.server.UnicastRemoteObject implements Calculator { public CalculatorImpl()throws java.rmi.RemoteException { super(); } public long add(long a,long b)throws java.rmi.RemoteException { return a+b; } public long sub(long a,long b)throws java.rmi.RemoteException { return a-b; } public long mul(long a,long b)throws java.rmi.RemoteException { return a*b; } public long div(long a,long b)throws java.rmi.RemoteException { return a/b; } } 12
Calculator Server: (CalculatorServer.java)
import java.rmi.*; public class CalculatorServer { public CalculatorServer() { try { Calculator c=new CalculatorImpl(); Naming.rebind("rmi://localhost:1099/CalculatorServer",c); } catch(Exception e) { System.out.println("Trouble :"+e); } } public static void main(String args[]) { new CalculatorServer(); } }
Calculator Client: (CalculatorClient.java)
import java.rmi.Naming; import java.rmi.RemoteException; import java.net.MalformedURLException; import java.rmi.NotBoundException; public class CalculatorClient { public static void main(String args[]) { try { Calculator c=(Calculator)Naming.lookup("rmi://localhost/CalculatorServer"); System.out.println(c.sub(4,3)); System.out.println(c.add(4,5)); System.out.println(c.mul(3,6)); System.out.println(c.div(9,3)); } 13
Result: Thus the program has been successfully executed and output is verified. 15
4. PERFORMING JAVA DATABASE CONNECTIVITY
Date: 07.02.2012 Aim: To perform Java DataBase Connectivity (JDBC) using java Application.
Procedure:
Step 1: select notepad ->create new document Step 2: write a code and save as java file Step 3: Create a table in Database. Step 4: Create new DSN name and connect the java file with Database
Step 5: compile the program and run the application Step 6: Add the data. Step 7: Stop the execution 16
Java Coding: (jdbc1.java)
import java.sql.*; public class jdbc1 { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:test"); Statement stat = con.createStatement(); stat.executeUpdate("create table emp(no int,name varchar(10))"); stat.executeUpdate("insert into emp values(1,'aaa')"); stat.executeUpdate("insert into emp values(2,'bbb')"); stat.executeUpdate("insert into emp values(3,'ccc')"); ResultSet rs = stat.executeQuery("select * from emp"); while(rs.next()) { int no = rs.getInt(1); String name = rs.getString(2); System.out.println(no + "\t" + name); System.out.println(); } con.close(); } catch(Exception e) { e.printStackTrace(); } } } 17
OUTPUT
Result: Thus the program has been successfully executed and output is verified. 18
5.JSP to JDBC Communication Date: 16.02.2012
Aim: To perform Java Database Connectivity (JDBC) using JSP.
Procedure:
Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: Open the saved application and write the coding in JSP Page.
Step 3: Open the MS Access and Create a Database and save the created table
Step 4: Next open the Control Panel Select->Administrative tools->Data Sources (ODBC)->and connect the database using Access Driver.
Step 5: Enter the details in JSP page and output will be displayed.
Result: Thus the program has been successfully executed and output is verified.
24
6. DESIGNING ONLINE APPLICATIONS WITH JSP
Date:23.02.2012 Aim: To Design online application by using JSP Page
Procedure:
Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: write coding in JSP page Step 3: create new html page and write coding Step 4: Save all and run the application Step 5: Enter the details in HTML page and output will be displayed in JSP Page Step 6: Stop the execution 25
HTML CODING
<html> <head> <Title>DESIGNING ONLINE APPLICATIONS WITH JSP</title> </head> <Body> <Form Method=Post Action="online.jsp"> <br><br><center><h1>DESIGNING ONLINE APPLICATIONS WITH JSP</h1><br><br> <h3> <pre> What's your name? What's your e-mail address? What's your age? <br> <br> <Input Type=Text Name=username><br> <Input Type=text Name=email><br> <Input Type=Text Name=age><br><br><br> <Input Type=Submit Value="Submit"></pre></h3> </center> </form> </body> </html> 26
Result: Thus the program has been successfully executed and output is verified. 28
7. CREATING JSP PROGRAM USING JAVABEAN
Date: 01.03.2012 Aim: To create JSP Program by using Java Bean.
Procedure:
Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: write a code in JSP Page.
Step 3: Build the program and run the application. Step 4: Stop the execution. 29
Jsp Coding
<html> <body> <%@page language="java"%> <% out.println("Today Date and time is"); %> <br> Date:<%=new java.util.Date()%> <br> </body> </html> 30
OUTPUT
Result: Thus the program has been successfully executed and output is verified.
31
8. E-MAIL APPLICATION WITH JSP Date:15.03.2012 Aim: To create E-Mail Application by using HTML and JSP page.
Procedure:
Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: write a code in JSP Page Step 3: Create new HTML Page and write a code Step 4: Save all and run the application Step 5: Enter the detail in HTML page and output will be displayed in JSP Page Step 6: Stop the execution 32
JSP PAGE <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Page</title> </head> <body> <% String email=request.getParameter("email"); %> <% if(email==null||email.equals("")) { %> Please Enter an email Address: <% } else { %> <blx: emailhost="www.gmail.com" from="[email protected]"> <blx: emailTo> <%=email%> </blx:emailTo></br> Thank you for registering With us </br> You Registered the following Name: </br> <%=request.getParameter("username")%></br> Your Registration was received at <%=new java.util.Date()%> Attached,Please find a content file: <blx: email Attach File="C:\Users\Nandhu\Desktop/wtrecord" content type="text/plain" name="content.txt"/> </blx:email> <%= email %> <%
Result: Thus the program has been successfully executed and output is verified 35
9. PERFORMING SESSION MANAGEMENT USING JSP Date:20.03.2012 Aim: To Perform Session Management Using JSP. Procedure: Step 1: Select->Net Beans IDE->New Project->Java web (Categories)->web applications (Project) Step 2: write a code in JSP Page Step 3: Create another three JSP Page and write the code. Step 4: Save all and run the application Step 5: Enter the detail in JSP page and output will be displayed in JSP page. Step 6: Stop the execution.