AJLabEx1to6 Without Border
AJLabEx1to6 Without Border
NO: 1
DATE:
ADDITION OF TWO NUMBERS USING RMI
Aim:
To add two Numbers using RMI concepts
Procedure:
1.Open four notepad and type the following code with the respective name as given in program. 2.Save all
the four files inside the folder rmi.
3.Open command prompt, go to rmi folder and compile all the four files using javac command. 4.Compile
the implementation program (AdderRemote.java) using the rmic command. 5.Open the rmi registry using
the command “start rmiregistry”. Minimize the rmi registry window. 6.Start the server using the command
“java”.
7.Open a new command prompt window, go to rmi folder and start the client using command “java”.
8.Exit from all the command prompt window.
Program :
1. Adder.java
import java.rmi.*;
public interface Adder extends Remote
{
public int add(int x,int y)throws RemoteException;
}
2. AdderRemote.java
3. MyServer.java
import java.rmi.*;
import java.rmi.registry.*;
public class MyServer{
public static void main(String args[]){
try{
Adder stub=new AdderRemote();
Naming.rebind("myobj",stub); }
catch(Exception e){
System.out.println(e);
}
}
}
4. MyClient.java
import java.rmi.*;
public class MyClient{
public static void main(String args[]){try{
Adder stub=(Adder)Naming.lookup("myobj");
System.out.println(stub.add(34,4));
}
catch(Exception e){}
}}
OUTPUT:
RESULT:
Thusthe program has been executed successfully and output verified.
EX.NO: 2
DATE:
CREATE APPLICATIONS USING JDBC
Aim:
To retrieve the records from employee table using Mysql Database and JDBC.
Procedure:
1.Open mysql command line and create a database, table and insert two rows of data into the table. a.
3.Type the name of the project as “myfirstdatabase” and select a location to save the project and click
Finish.
4.In the project tab
right click the library folder of your application and select the option “Add JAR/Folder” and go to the
location where we have saved our mysql connector JAR file. Select the JAR file and it will be added to
your project.
5.Type the following code in the main method.
6.Run the code by clicking the run tool or by selecting run option from run menu.
Program
package myfirstdatabase;
import java.sql.*;
public class Myfirstdatabase
{
public static void main(String[] args)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","mysql"); Statement
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from employee");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Output:
RESULT:
Thusthe program has been executed successfully and output verified.
EX.NO: 3
DATE:
CREATE STUDENT APPLICATIONS USING JDBC
Aim:
To create a student application using MySQL Database and JDBC.
Procedure :
1. Open mysql command line and create a database and table as given below:
Output:
1. Inserting 2 rows :
Aim:
Develop simple Login Application using Servlet.
Procedure:
1.Start Netbeans IDE, Go to file menu and select new project, the new project dialog box shown as
below opens. From the Categories select the option “java web” and from projects select “web
Application” and click Next.
2.Type the name of the project as “ServApp” and select a location to save the project and click Next.
3.In the server select default server “GlassFish Server” and click “Next”. Click “Finish”. 4.Type the
index.html code in the respective index .html file.
5.Right click the source packages folder from the workspace and select option “new” and select
“servlet” and type the name of the servlet as “LoginServlet” click “Next”. Select the check box “Add
information to deployment descriptor” and then click “Finish”.
6.Run the index.html by right clicking the file and select run.
Program :
Index.html
<html>
<head>
<title>Login Form</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="post" action="LoginServlet">
Email ID:<input type="text" name="email" ><br/>
Password:<input type="password" name="pass" /><br/>
<input type="submit" value="login" />
</form>
LoginServlet.java
import java.io.*;
importjavax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet
{
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String user = request.getParameter("email");
String pass = request.getParameter("pass");
if(user.equals("srm")&& pass.equals("123"))
{
out.println("Welcome to oursite" + user);
}
else
{
out.println("Username or Password incorrect!! Try Again");
}}
OUTPUT:
RESULT:
Thusthe programhas been executed successfully and output verified.
EX.NO: 5
DATE:
TO CREATE USER LOGIN FORM USING SERVLET
Aim:
To create the user Login page and to Read the Form Data using Servlet
Procedure:
1.Start Netbeans IDE, Go to file menu and select new project, the new project dialog box shown as
below opens. From the Categories select the option “java web” and from projects select “web
Application” and click Next.
2.Type the name of the project as “LoginServlet” and select a location to save the project and click
Next.
3.In the server select default server “GlassFish Server” and click “Next”. Click
“Finish”. 4.Type the index.html code in the respective index .html file.
5.Right click the source packages folder from the workspace and select option “new” and select
“servlet” and type the name of the servlet as “GetForm” click “Next”. Select the check box “Add
information to deployment descriptor” and then click “Finish”.
6.Run the index.html by right clicking the file and select run.
Program:
index.html
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<formaction = "RegisterForm" method = "GET">
First Name: <input type = "text" name = "first_name"><br />
Last Name: <input type = "text" name = "last_name" /><br />
Address: <input type = "text" name = "address"/><br />
Email: <input type = "text" name = "email"/><br />
<input type = "submit" value = "Submit" />
</form>
</body>
</html>
GetForm.java
import java.io.*;
importjavax.servlet.*;
import javax.servlet.http.*;
public class GetForm extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException
{
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String title = "Using GET Method to Read FormData";
StringdocType = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n"; out.println(docType +"<html>\n"
+ "<head><title>" + title + "</title></head>\n" +"<body bgcolor = \"pink\">\n" +
"<h1 align = \"center\">" + title + "</h1>\n" +"<ul>\n" +" <li><b>First Name</b>: "
+ request.getParameter("first_name") + "\n" + "<li><b>Last Name</b>: " +
request.getParameter("last_name") + "\n" + "<li><b>Address</b>: "
+ request.getParameter("address") + "\n" + "<li><b>Email</b>: "
+ request.getParameter("email") + "\n" + "</ul>\n" +"</body>"
+"</html>"); }}
OUTPUT
RESULT: Thusthe programhas been executed successfully and output verified.
EX.NO: 6
DATE:
SESSION MANAGEMENT USING SERVLET
AIM:
To perform session management using servlet.
PROCEDURE:
1.Start Netbeans IDE, Go to file menu and select new project, the new project dialog box shown as
below opens. From the Categories select the option “java web” and from projects select “web
Application” and click Next.
2.Type the name of the project as “Sess” and select a location to save the project and click Next.
3.In the server select default server “GlassFish Server” and click “Next”. Click “Finish”. 4.Type
the index.html code in the respective index .html file.
5.Right click the source packages folder from the workspace and select option “new” and select
“servlet” and type the name of the servlet as “FirstServlet” click “Next”. Select the check box
“Add information to deployment descriptor” and then click “Finish”. Type its code. 6.Repeat
step 5 and create another servlet with the name “SecondServlet” and type its code. 7.Run the
index.html by right clicking the file and select run.
PROGRAM:
FirstServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class FirstServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse
response) throwsServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("userName");
out.print("Welcome "+n);
out.print("<a href='SecondServlet?uname="+n+"'>visit</a>");
out.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
processRequest(request, response); }
Second Servlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SecondServlet extends HttpServlet{
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String n=request.getParameter("uname");
out.print("Hello "+n);
out.close();
}
protected void doPost (HttpServletRequest request, HttpServletResponse
response)throws ServletException, IOException {
processRequest(request, response); }}
Index.html
<html>
<body>
<form action="FirstServlet" method="post">
Name:<input type="text" name="userName"/><br/>
<input type="submit" value="go"/>
</form>
</body>
</html>
OUTPUT:
RESULT:
Thusthe programhas been executed successfully and output verified.