0% found this document useful (0 votes)
7 views50 pages

PG Java Record

The document outlines a series of exercises for creating web applications using Java, Servlets, and JSP with NetBeans IDE. It includes step-by-step procedures for displaying a welcome message, designing a purchase order form, and calculating student marks percentage. Each exercise provides code examples and expected outcomes, demonstrating successful execution of the projects.

Uploaded by

deepikavengalam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views50 pages

PG Java Record

The document outlines a series of exercises for creating web applications using Java, Servlets, and JSP with NetBeans IDE. It includes step-by-step procedures for displaying a welcome message, designing a purchase order form, and calculating student marks percentage. Each exercise provides code examples and expected outcomes, demonstrating successful execution of the projects.

Uploaded by

deepikavengalam
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CONTENTS

[Link] Date TITLE Page No Signature


.
01 DISPLAY A WELCOME MESSAGE USING
SERVLET
DESIGN A PURCHASE ORDER FORM
02
USING HTML FORM AND SERVLET
DEVELOP A PROGRAM FOR
03 CALCULATING THE PERCENTAGE OF
MARKS OF A STUDENT USING JSP

04 DESIGN A PURCHASE ORDER FORM


USING HTML FORM AND JSP

05 PREPARE A EMPLOYEE PAYSLIP USING


JSP
WRITE A PROGRAM USING JDBC FOR
CREATING A TABLE , INSERTING,
06
DELETING RECORDS AND LIST OUT
THE RECORDS

WRITE A PROGRAM USING JAVA


07
SERVLET TO HANDLE FORM DATA

WRITE A SIMPLE SERVLET PROGRAM


TO CREATE A TABLE OF ALL THE
08 HEADERS IT RECEIVES ALONG WITH
THEIR ASSOCIATED VALUES
WRITE A PROGRAM IN JSP BY USING
09
SESSION OBJECT

WRITE A PROGRAM TO BUILD A SIMPLE


10 CLIENT SERVER APPLICATION USING
RMI

CREATE AN APPLET FOR A


11
CALCULATOR APPLICATION

PROGRAM TO SEND A TEXT MESSAGE


TO ANOTHER SYSTEM AND RECEIVE
12
THE TEXT MESSAGE FROM THE
SYSTEM(USE SOCKET PROGRAMMING
[Link]. 01 DISPLAY A WELCOME MESSAGE USING
Date: SERVLET

AIM:
To create a project for Display a welcome message using Servlet Program in Java with
Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.


Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.
Step 3: Create a Servlet Page in the project tab ->Right Click on the Source
Packages Floder.
Step 4: Now Choose New -> Servlet ->Class Name -> Finish.
Step 5: After you complete the Coding -> Right click to choose the Clean and
Build.
Step 6: Run the Project
Step 7: Right-click on the project in the Projects tab and select Run.
Step 8: Now, The browser should automatically open, displaying the welcome
message.
Step 9: Stop the Project.
PROGRAM:

Servlet ([Link]):
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
*
* @author RKS PG LAB 08
*/
public class NewServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
[Link]("text/html;charset=UTF-8");
try (PrintWriter out = [Link]()) {
/* TODO output your page here. You may use following sample code. */
[Link]("<!DOCTYPE html>");
[Link]("<html>");
[Link]("<head>");
[Link]("<title>Servlet NewServlet</title>");
[Link]("</head>")
[Link]("<body>");
[Link]("<h1> Welcome a servlet page " + "</h1>");
[Link]("</body>");
[Link]("</html>");
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the


left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}
HTML([Link]):
<!--

To change this license header, choose License Headers in Project Properties.

To change this template file, choose Tools | Templates

and open the template in the editor.

-->

<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>

<form action="NewServlet" method="GET">

<center>

<h3> This is a servlet program</h3>

<p>Name: <input type="text" name="username"></p>

<p><input type="submit" value="login" </p>

</center>

</form>

</body>

</html>
OUTPUT:
RESULT:
Thus the Project for Display a welcome message using a Servlet in Java with NetBeans
IDE 1.8 was executed Successfully

[Link]. 02 DESIGN A PURCHASE ORDER FORM USING


Date: HTML FORM AND SERVLET

AIM:
To create a project for Design a Purchase Order form using HTML and Servlet Program
in Java with Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.

Step 3: First Create a HTML Form Page -> Right Click on the Source Packages Floder.

Step 4: Now Choose -> New -> HTML ->Class Name -> Finish.

Step 5: Second Create a Servlet Page-> Right Click on the Source Packages Floder.

Step 6: Now Choose -> New -> Servlet->Class Name -> Finish.

Step 7: After you complete the Coding -> Right click to choose the Clean and Build.

Step 8: Run the Project

Step 9: Right-click on the project in the Projects tab and select Run.

Step 10: Now, The browser should automatically open, displaying the Output page.

Step 11: Stop the Project.

PROGRAM:

Create HTML Form ([Link]):


<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<title>Purchase Order Form</title>
</head>
<body>
<h2>Purchase Order Form</h2>
<form action="SubmitOrderServlet" method="post">
<fieldset>
<legend>Customer Information</legend>
<label for="customerName">Customer Name:</label>
<input type="text" id="customerName" name="customerName" required><br><br>

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
</fieldset>

<fieldset>
<legend>Order Information</legend>
<label for="itemName">Item Name:</label>
<input type="text" id="itemName" name="itemName" required><br><br>

<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" required min="1"><br><br>

<label for="price">Price per Item:</label>


<input type="number" id="price" name="price" required min="0.01"
step="0.01"><br><br>

<label for="orderDate">Order Date:</label>


<input type="date" id="orderDate" name="orderDate" required><br><br>
</fieldset>

<input type="submit" value="Submit Order">


</form>
</body>
</html>
Create Servlet ([Link]):
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

import [Link].*;
import [Link].*;
import [Link].*;

public class SubmitOrderServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
// Setting response content type
[Link]("text/html");

// Getting form data from request


String customerName = [Link]("customerName");
String email = [Link]("email");
String itemName = [Link]("itemName");
int quantity = [Link]([Link]("quantity"));
double price = [Link]([Link]("price"));
String orderDate = [Link]("orderDate");

// Calculate total cost


double totalCost = quantity * price;

// Generate HTML response to display order details


PrintWriter out = [Link]();
[Link]("<html><body>");
[Link]("<h2>Order Submitted Successfully</h2>");
[Link]("<p><strong>Customer Name:</strong> " + customerName + "</p>");
[Link]("<p><strong>Email:</strong> " + email + "</p>");
[Link]("<p><strong>Item Ordered:</strong> " + itemName + "</p>");
[Link]("<p><strong>Quantity:</strong> " + quantity + "</p>");
[Link]("<p><strong>Price per Item:</strong> $" + price + "</p>");
[Link]("<p><strong>Order Date:</strong> " + orderDate + "</p>");
[Link]("<p><strong>Total Cost:</strong> $" + totalCost + "</p>");
[Link]("<br><br>");
[Link]("<a href='[Link]'>Go Back to Purchase Order Form</a>");
[Link]("</body></html>");
}

@Override
public String getServletInfo() {
return "Servlet to process purchase order form submission.";
}
}

OUTPUT:
RESULT:
Thus the Project for Design a Purchase Order form using Html form and Servlet program
in Java with Netbeans IDE 8.1 was executed Successfully.

[Link]. 03 DEVELOP A PROGRAM FOR CALCULATING


Date: THE PERCENTAGE OF MARKS OF A STUDENT
USING JSP

AIM:
To create a project for Develop a Program for Calculating the Percentage of Marks of
a Student Using JSP Program in Java with Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.

Step 3: Create a JSP Page in the project tab ->Right Click on the Source Packages Floder.

Step 4: Now Choose -> New -> JSP ->Class Name -> Finish.

Step 5: After you complete the Coding -> Right click to choose the Clean and Build.

Step 6: Run the Project

Step 7: Right-click on the project in the Projects tab and select Run.

Step 8: Now, The browser should automatically open, displaying the Output page.

Step 9: Stop the Project.

PROGRAM:

JSP Page ([Link]):


<%--
Document : calculatePercentage
Created on : 3 Jan, 2025, 2:48:09 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Percentage Calculator</title>
</head>
<body>
<h2>Percentage Calculator</h2>
<form action="[Link]" method="post">
<label for="subject1">Subject 1 Marks:</label>
<input type="number" id="subject1" name="subject1" required><br><br>
<label for="subject2">Subject 2 Marks:</label>
<input type="number" id="subject2" name="subject2" required><br><br>
<label for="subject3">Subject 3 Marks:</label>
<input type="number" id="subject3" name="subject3" required><br><br>
<input type="submit" value="Calculate Percentage">
</form>
<%-- Calculate Percentage --%>
<%
if([Link]().equalsIgnoreCase("POST")) {
// Retrieve marks from the form
int subject1 = [Link]([Link]("subject1"));
int subject2 = [Link]([Link]("subject2"));
int subject3 = [Link]([Link]("subject3"));
// Calculate percentage
double totalMarks = subject1 + subject2 + subject3;
double percentage = (totalMarks / 300) * 100;
%>
<h3>Result:</h3>
<p>Total Marks: <%= totalMarks %></p>
<p>Percentage: <%= [Link]("%.2f", percentage) %>%</p>
<% } %>
</body>
</html>

OUTPUT:
RESULT:
Thus the Project for Develop a program for calculating the percentage of marks of a
student using JSP program in Java with Netbeans IDE 8.1 was executed Successfully.

[Link]. 04 DESIGN A PURCHASE ORDER FORM USING


Date: HTML FORM AND JSP
AIM:
To create a project for Design a Purchase Order form using HTML and JSP Program in
Java with Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.

Step 3: First Create a HTML Form Page -> Right Click on the Source Packages Floder.

Step 4: Now Choose -> New -> HTML ->Class Name -> Finish.

Step 5: Second Create a JSP Page -> Right Click on the Source Packages Floder.

Step 6: Now Choose -> New -> JSP ->Class Name -> Finish.

Step 7: After you complete the Coding -> Right click to choose the Clean and Build.

Step 8: Run the Project

Step 9: Right-click on the project in the Projects tab and select Run.

Step 10: Now, The browser should automatically open, displaying the Output page.

Step 11: Stop the Project.

PROGRAM:

HTML Page ([Link]):

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Order Form</title>
</head>
<body>
<h2>Purchase Order Form</h2>
<form action="[Link]" method="post">
<label for="product">Product:</label>
<input type="text" id="product" name="product" required><br><br>
<label for="quantity">Quantity:</label>
<input type="number" id="quantity" name="quantity" required><br><br>
<label for="price">Price:</label>
<input type="text" id="price" name="price" required><br><br>
<label for="supplier">Supplier:</label>
<input type="text" id="supplier" name="supplier" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
JSP Page ([Link]):
<%--
Document : processPurchaseOrder
Created on : 30 Jan, 2025, 3:49:38 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Order Confirmation</title>
</head>
<body>
<h2>Purchase Order Confirmation</h2>
<%-- Retrieve form data --%>
<% String product = [Link]("product"); %>
<% int quantity = [Link]([Link]("quantity")); %>
<% double price = [Link]([Link]("price")); %>
<% String supplier = [Link]("supplier"); %>
<%-- Process the data (you can save it to a database or perform any other
business logic) --%>
<%-- For simplicity, we'll just print the data to the page in this example --%>
<p><strong>Product:</strong> <%= product %></p>
<p><strong>Quantity:</strong> <%= quantity %></p>
<p><strong>Price:</strong> <%= price %></p>
<p><strong>Supplier:</strong> <%= supplier %></p>
<p>Thank you for your purchase!</p>
</body>
</html>

OUTPUT:
RESULT:
Thus the Project for Design a Purchase Order form using HTML and JSP Program in Java
with Netbeans IDE 8.1 was executed Successfully.

[Link]. 05 PREPARE A EMPLOYEE PAYSLIP USING JSP


Date:
AIM:
To create a project for Prepare a Employee Payslip Using JSP Program in Java with
Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.

Step 3: First Create a JSP Page -> Right Click on the Source Packages Floder.

Step 4: Now Choose -> New -> JSP ->Class Name -> Finish.

Step 5: Second Create a another JSP Page -> Right Click on the Source Packages Floder.

Step 6: Now Choose -> New -> JSP ->Class Name -> Finish.

Step 7: After you complete the Coding -> Right click to choose the Clean and Build.

Step 8: Run the Project

Step 9: Right-click on the project in the Projects tab and select Run.

Step 10: Now, The browser should automatically open, displaying the Output page.

Step 11: Stop the Project.

PROGRAM:

JSP Page ([Link]):


<%--
Document : employeePaySlip
Created on : 30 Jan, 2025, 2:38:09 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Employee Pay Slip</title>
</head>
<body>
<h2>Employee Pay Slip</h2>
<form action="[Link]" method="post">
<label for="employeeName">Employee Name:</label>
<input type="text" id="employeeName" name="employeeName"
required><br><br>
<label for="basicSalary">Basic Salary:</label>
<input type="number" id="basicSalary" name="basicSalary"
required><br><br>
<label for="allowance">Allowance:</label>
<input type="number" id="allowance" name="allowance"
required><br><br>
<input type="submit" value="Calculate Pay Slip">
</form>
</body>
</html>

JSP Page ([Link]):


<%--
Document : calculatePay
Created on : 30 Jan, 2025, 2:40:40 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pay Slip Calculation</title>
</head>
<body>
<h2>Pay Slip Calculation</h2>
<%-- Retrieve form data --%>
<% String employeeName = [Link]("employeeName"); %>
<% double basicSalary =
[Link]([Link]("basicSalary")); %>
<% double allowance =
[Link]([Link]("allowance")); %>
<%-- Calculate total salary --%>
<% double totalSalary = basicSalary + allowance; %>
<p><strong>Employee Name:</strong> <%= employeeName %></p>
<p><strong>Basic Salary:</strong> <%= basicSalary %></p>
<p><strong>Allowance:</strong> <%= allowance %></p>
<hr>
<p><strong>Total Salary:</strong> <%= totalSalary %></p>
</body>
</html>

OUTPUT:
RESULT:
Thus the Project for Prepare a Employee Payslip Using JSP Program in Java with
Netbeans IDE 8.1 was executed Successfully.

[Link]. 06 WRITE A PROGRAM USING JDBC FOR


CREATING A TABLE , INSERTING, DELETING
Date:
RECORDS AND LIST OUT THE RECORDS

[Link]. 07 WRITE A PROGRAM USING JAVA SERVLET TO


Date: HANDLE FORM DATA
AIM:
To create a project for Write a Program Using Java Servlet tohandle form data
Program in Java with Netbeans 8.1.

PROCEDURE:

Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.

Step 3: First Create a Servlet Page -> Right Click on the Source Packages Floder.

Step 4: Now Choose -> New -> Servlet ->Class Name -> Finish.

Step 5: Second Create a HTML Form Page -> Right Click on the Source Packages
Floder.

Step 6: Now Choose -> New -> HTML ->Class Name -> Finish.

Step 7: After you complete the Coding -> Right click to choose the Clean and
Build.

Step 8: Run the Project

Step 9: Right-click on the project in the Projects tab and select Run.

Step 10: Now, The browser should automatically open, displaying the Output
page.

Step 11: Stop the Project.

PROGRAM:

Servlet ([Link]):

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
@WebServlet("/FormDataServlet")
public class FormDataServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {
// Set response content type
[Link]("text/html");
// Get the PrintWriter object
PrintWriter out = [Link]();
// Retrieve form data
String firstName = [Link]("firstName");
String lastName = [Link]("lastName");
String email = [Link]("email");
// Process the data (you can save it to a database or perform any other business logic)
// For simplicity, we'll just print the data to the response
[Link]("<html><head><title>Form Data Processing</title></head><body>");
[Link]("<h2>Form Data Processing</h2>");
[Link]("<p>First Name: " + firstName + "</p>");
[Link]("<p>Last Name: " + lastName + "</p>");
[Link]("<p>Email: " + email + "</p>");
[Link]("</body></html>");
}
}
HTML Form ([Link]):
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Data Submission</title>
</head>
<body>
<h2>Form Data Submission</h2>
<form action="FormDataServlet" method="post">
<label for="firstName">First Name:</label>
<input type="text" id="firstName" name="firstName" required><br><br>
<label for="lastName">Last Name:</label>
<input type="text" id="lastName" name="lastName" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Output:
RESULT:
Thus the Project for Write a Program Using Java Servlet to handle form data Program in
Java with Netbeans IDE 8.1 was executed Successfully.
WRITE A SIMPLE SERVLET PROGRAM TO
CREATE A TABLE OF ALL THE HEADERS IT
[Link]. 08
Date: RECEIVES ALONG WITH THEIR ASSOCIATED
VALUES

[Link]. 09 WRITE A PROGRAM IN JSP BY USING SESSION


Date: OBJECT

AIM:
To create a project for Write a Program Using Java Servlet tohandle form data Program
in Java with Netbeans 8.1.

PROCEDURE:
Step 1: Start the Project.

Step 2: Create A New Project Using File Menu -> New Project -> Java Web->Web
Application-> Next -> Project Name -> Next -> Finish.
Step 3: In this program to create a 4 JSP pages
Step 4: First Create a JSP Page -> Right Click on the Source Packages Floder.
Step 5: Now Choose -> New -> JSP ->Class Name -> Finish.
Step 6: Second Create a JSP Page -> Right Click on the Source Packages Floder.
Step 7: Now Choose -> New -> JSP ->Class Name -> Finish.
Step 8: Third Create a another JSP Page -> Right Click on the Source Packages Floder.
Step 9: Now Choose -> New -> JSP ->Class Name -> Finish.
Step 10: Fourth Create a another JSP Page -> Right Click on the Source Packages Floder.
Step 11: Now Choose -> New -> JSP ->Class Name -> Finish.
Step 12: After you complete the Coding -> Right click to choose the Clean and Build.

Step 13: Run the Project

Step 14: Right-click on the project in the Projects tab and select Run.

Step 15: Now, The browser should automatically open, displaying the Output
page.

Step 16: Stop the Project.

PROGRAM:
JSP Page ([Link]):

<%--
Document : userInfo
Created on : 4 Feb, 2025, 12:52:28 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Information</title>
</head>
<body>
<h2>User Information</h2>
<%-- Retrieve user information from the session --%>
<% String username = (String) [Link]("username"); %>
<% String email = (String) [Link]("email"); %>
<p>Welcome, <%= username %>!</p>
<p>Your email: <%= email %></p>
<p><a href="[Link]">Logout</a></p>
</body>
</html>
JSP Page ([Link]):
<%--
Document : login
Created on : 4 Feb, 2025, 12:54:15 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
</head>
<body>
<h2>Login</h2>
<form action="[Link]" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Login">
</form>
</body>
</html>
JSP Page ([Link]):
<%--
Document : loginAction
Created on : 4 Feb, 2025, 12:56:54 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<%@ page import="[Link].*, [Link].*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login Action</title>
</head>
<body>
<h2>Login Action</h2>
<%-- Retrieve user inputs from the form --%>
<% String username = [Link]("username"); %>
<% String email = [Link]("email"); %>
<%-- Store user information in the session --%>
<% [Link]("username", username); %>
<% [Link]("email", email); %>
<p>Login successful!</p>
<p><a href="[Link]">View User Information</a></p>
</body>
</html>
JSP Page ([Link]):
<%--
Document : logout
Created on : 4 Feb, 2025, 12:58:16 PM
Author : RKS PG LAB 08
--%>

<%@ page language="java" contentType="text/html; charset=UTF-8"


pageEncoding="UTF-8"%>
<%@ page import="[Link].*, [Link].*" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Logout</title>
</head>
<body>
<h2>Logout</h2>
<%-- Invalidate the session to log out the user --%>
<% [Link](); %>
<p>Logout successful!</p>
<p><a href="[Link]">Login Again</a></p>
</body>
</html>

OUTPUT:
RESULT:
Thus the Project for Write a Program in JSP by Using Session Object Program in Java with
Netbeans IDE 8.1 was executed Successfully.
[Link]. 10 WRITE A PROGRAM TO BUILD A SIMPLE

Date: CLIENT SERVER APPLICATION USING RMI


[Link]. 11 CREATE AN APPLET FOR A CALCULATOR
APPLICATION
Date:

[Link]. 12 PROGRAM TO SEND A TEXT MESSAGE TO


Date: ANOTHER SYSTEM AND RECEIVE THE TEXT
MESSAGE FROM THE SYSTEM(USE SOCKET
PROGRAMMING)

AIM:

To create a Program to Send a text message to another System and receive


the text message from the System (use socket Programming) in java using
Notepad.

PROCEDURE:

Step 1: Start the Program.

Step 2: Open the Notepad.

Step 3: Save the Server code in a file named [Link].

Step 4: Open another Notepad.

Step 5: Save the Client code in a file named [Link].

Step 6: Compile both files using javac [Link] and javac [Link].

Step 7: Start the server by running java Server in one terminal.

Step 8: Start the client by running java Client in another terminal.

Step 9: Type a message on the client side, and the server will receive and print the

Message.

Step 10: Stop the Program.

PROGRAM:
Server Side Code:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Server {
public static void main(String[] args) {
final int PORT = 5000;
try {
// Create a ServerSocket
ServerSocket serverSocket = new ServerSocket(PORT);
[Link]("Server is waiting for a connection...");
// Wait for a client to connect
Socket clientSocket = [Link]();
[Link]("Client connected.");
// Create a BufferedReader to read messages from the client
BufferedReader reader = new BufferedReader(new
InputStreamReader([Link]()));
// Read and print messages from the client
String message;
while ((message = [Link]()) != null) {
[Link]("Received from client: " + message);
}
// Close resources
[Link]();
[Link]();
[Link]();
} catch (IOException e) {
[Link]();
}
}
}
Client Side Code:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class Client {
public static void main(String[] args) {
final String SERVER_IP = "[Link]"; // Change this to the server's IP address
final int SERVER_PORT = 5000;
try {
// Connect to the server
Socket socket = new Socket(SERVER_IP, SERVER_PORT);
// Create a PrintWriter to send messages to the server
PrintWriter writer = new PrintWriter([Link](), true);
// Create a BufferedReader to read messages from the console
BufferedReader consoleReader = new BufferedReader(new InputStreamReader([Link]));
// Read messages from the console and send them to the server
String message;
[Link]("Type a message (type 'exit' to close the connection):");
while ((message = [Link]()) != null && ![Link]("exit")) {
[Link](message);
}
// Close resources
[Link]();
[Link]();
[Link]();
} catch (IOException e) {
[Link]();
}
}
}

OUTPUT:
RESULT:
Thus the Project for a Program to send a text message to another System and Receiver the
text message from the System (Use Socket Programming) was executed successfully.

You might also like