Wa0007.

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Program 13: Write an HTML code to demonstrate the usage of inline CSS, internal CSS,

external CSS and imported CSS.

HTML File

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>CSS Demonstration</title>

<!-- Internal CSS -->

<style>

body {

font-family: 'Arial', sans-serif; /* Applies to the whole page */

.internal-style {

color: green; /* Internal CSS for class */

@import url("imported_styles.css"); /* CSS Import inside internal CSS */

</style>

<!-- External CSS -->

<link rel="stylesheet" href="styles.css">

</head>

<body>

<h1 style="color: blue;">Inline CSS Example</h1> <!-- Inline CSS -->

<p class="internal-style">This paragraph is styled with internal CSS.</p>

<p class="external-style">This paragraph is styled with external CSS.</p>


<p class="imported-style">This paragraph is styled with imported CSS.</p>

</body>

</html>

External CSS file

.external-style {

color: red; /* CSS for class defined in an external stylesheet */ font-size: 16px;

CSS file that is imported

.imported-style {

color: purple; /* CSS for class defined in an imported stylesheet */ font-weight: bold;

}
Program no.=14

Write programs using Java script for Web Page to display browsers information.

<!DOCTYPE html>

<html>

<head>

<title>Browser Information</title>

</head>

<body>

<h1>Browser Information</h1>

<p id="browserInfo"></p>

<script>

// Function to display browser information

function displayBrowserInfo() {

var browserInfo = "Browser Name: " + navigator.appName +

<br>";

browserInfo += "Browser Version: " + navigator.appVersion + "<br>";

browserInfo += "Cookies Enabled: " + navigator.cookieEnabled + "<br>";

browserInfo += "Platform: " + navigator.platform + "<br>";

browserInfo += "User Agent: " + navigator.userAgent + "<br>";

document.getElementById("browserInfo").innerHTML = browserInfo;

}
// Call the function to display browser information

displayBrowserInfo();

</script>

</body>

</html>
Program no. =15

Write a Java script to validate Name, Mobile Number, Email

Id and Password.

• Name must contain alphabets and whitespace only

• Mobile number must be 10 digits only.

• Email Id must have one “@”, and domain name is

“united.ac.in”

• Password must have atleast one alphabet, one digit and

one special character (!@#$%&*)

<!DOCTYPE html>

<html>

<head>

<title>Form Validation</title>

<script>

function validateForm() {

var name = document.getElementById("name").value;

var mobileNumber = document.getElementById("mobileNumber").value;

var email = document.getElementById("email").value;

var password = document.getElementById("password").value;

var namePattern = /^[a-zA-Z\s]+$/;

var mobilePattern = /^\d{10}$/;

var emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;

var passwordPattern = /^(?=.[A-Za-z])(?=.\d)(?=.[!@#$%&])[A-Za-z\d!@#$%&*]{8,}$/;


if (!name.match(namePattern)) {

alert("Name must contain alphabets and whitespace only.");

return false;

if (!mobileNumber.match(mobilePattern)) {

alert("Mobile number must be 10 digits only.");

return false;

if (!email.match(emailPattern)) {

alert("Email Id must have one '@', and domain name is 'united.ac.in'.");

return false;

if (!password.match(passwordPattern)) {

alert("Password must have at least one alphabet, one digit, and one special
character (!@#$%&*), and be at least 8 characters long.");

return false;

return true;

</script>

</head>

<body>
<h1>Form Validation</h1>

<form onsubmit="return validateForm()">

Name: <input type="text" id="name"><br>

Mobile Number: <input type="text" id="mobileNumber"><br>

Email: <input type="text" id="email"><br>

Password: <input type="password" id="password"><br>

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

</form>

</body>

</html>
Program no. =16

16 Writing program in XML for creation of DTD which specifies set of rules. Create a style
sheet in CSS/ XSL & display the document in internet explore.

<?xml version="1.0"?>

<!DOCTYPE data SYSTEM "example.dtd">

<data>

<name>John Doe</name>

<age>30</age>

</data>

example.dtd:

<!ELEMENT data (name, age)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT age (#PCDATA)>

Style Sheet in CSS/XSL: Create a CSS file (style.css) to style the XML document:

style.css:

data {

font-family: Arial, sans-serif;

color: blue;

name {
font-weight: bold;

age {

color: green;

}
Program no. = 17

Write a program to implement Math server using TCP socket and also write a client program
to send user input to Math server and display response as the square of the given number.

MathServer.java:

import java.io.*;

import java.net.*;

public class MathServer {

public static void main(String[] args) {

try {

ServerSocket serverSocket = new ServerSocket(1234);

System.out.println("Math Server is running...");

while (true) {

Socket clientSocket = serverSocket.accept();

System.out.println("Client connected: " + clientSocket);

BufferedReader in = new BufferedReader(new


InputStreamReader(clientSocket.getInputStream()));

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

String input = in.readLine();

int number = Integer.parseInt(input);


int square = number * number;

out.println("Square of " + number + " is: " + square);

clientSocket.close();

} catch (IOException e) {

e.printStackTrace();

MathClient.java:

import java.io.*;

import java.net.*;

public class MathClient {

public static void main(String[] args) {

try {

Socket socket = new Socket("localhost", 1234);

BufferedReader userInput = new BufferedReader(new


InputStreamReader(System.in));

BufferedReader in = new BufferedReader(new


InputStreamReader(socket.getInputStream()));

PrintWriter out = new PrintWriter(socket.getOutputStream(), true);


System.out.print("Enter a number: ");

String number = userInput.readLine();

out.println(number);

String response = in.readLine();

System.out.println("Server response: " + response);

socket.close();

} catch (IOException e) {

e.printStackTrace();

}
Program no.=18

Write a program to illustrate CURD operations using JDBC connectivity with MySQL
database.

CREATE TABLE students (

id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(50),

age INT

);

CRUDOperations.java:

import java.sql.*;

public class CRUDOperations {

static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";

static final String DB_URL = "jdbc:mysql://localhost/your_database_name";

static final String USER = "your_username";

static final String PASS = "your_password";

public static void main(String[] args) {

Connection conn = null;

Statement stmt = null;

try {

Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DB_URL, USER, PASS);

stmt = conn.createStatement();

// Create operation

String createQuery = "INSERT INTO students (name, age) VALUES ('Alice', 25)";

stmt.executeUpdate(createQuery);

// Read operation

String readQuery = "SELECT * FROM students";

ResultSet rs = stmt.executeQuery(readQuery);

while (rs.next()) {

System.out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Age:


" + rs.getInt("age"));

// Update operation

String updateQuery = "UPDATE students SET age = 30 WHERE name = 'Alice'";

stmt.executeUpdate(updateQuery);

// Delete operation

String deleteQuery = "DELETE FROM students WHERE name = 'Alice'";

stmt.executeUpdate(deleteQuery);

rs.close();

stmt.close();

conn.close();
} catch (SQLException se) {

se.printStackTrace();

} catch (Exception e) {

e.printStackTrace();

} finally {

try {

if (stmt != null) stmt.close();

} catch (SQLException se2) {

try {

if (conn != null) conn.close();

} catch (SQLException se) {

se.printStackTrace();

}
Program no. = 19

Write a SQL query to create and call the stored procedures with following specifications:

• Procedure without parameter and no return type

• Procedure with parameter and no return type

• Procedure with parameter and with return type

Procedure without parameter and no return type:

DELIMITER //

CREATE PROCEDURE sp_no_param_no_return()

BEGIN

SELECT 'Hello, World!' AS Message;

END //

DELIMITER ;

Procedure with parameter and no return type:

DELIMITER //

CREATE PROCEDURE sp_with_param_no_return(IN input_name VARCHAR(50))

BEGIN

SELECT CONCAT('Hello, ', input_name) AS Message;

END //

DELIMITER ;

Procedure with parameter and with return type:

DELIMITER //

CREATE PROCEDURE sp_with_param_with_return(IN input_number INT, OUT


result_square INT)

BEGIN
SET result_square = input_number * input_number;

END //

DELIMITER ;

Calling Procedure without parameter and no return type:

CALL sp_no_param_no_return();

Calling Procedure with parameter and no return type:

SET @name = 'Alice';

CALL sp_with_param_no_return(@name);

Calling Procedure with parameter and with return type:

SET @number = 5;

CALL sp_with_param_with_return(@number, @result);

SELECT @result AS SquareResult;


Program no. = 20

Write a program to illustrate CURD operations using JSP connectivity with MySQL database
on Apache Tomcat web server.

CREATE TABLE students (

id INT AUTO_INCREMENT PRIMARY KEY,

name VARCHAR(50),

age INT

);

CreateStudent.jsp (for Create operation):

<%@ page import="java.sql.*" %>

<%

String name = request.getParameter("name");

int age = Integer.parseInt(request.getParameter("age"));

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/your_database_name",
"your_username", "your_password");

PreparedStatement pstmt = conn.prepareStatement("INSERT INTO students (name, age)


VALUES (?, ?)");

pstmt.setString(1, name);

pstmt.setInt(2, age);

pstmt.executeUpdate();
out.println("Student created successfully!");

pstmt.close();

conn.close();

%>

ReadStudents.jsp (for Read operation):

<%@ page import="java.sql.*" %>

<%

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/your_database_name",
"your_username", "your_password");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM students");

while (rs.next()) {

out.println("ID: " + rs.getInt("id") + ", Name: " + rs.getString("name") + ", Age: " +
rs.getInt("age") + "<br>");

rs.close();

stmt.close();

conn.close();

%>

UpdateStudent.jsp (for Update operation):

<%@ page import="java.sql.*" %>

<%

int id = Integer.parseInt(request.getParameter("id"));
int newAge = Integer.parseInt(request.getParameter("newAge"));

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/your_database_name",
"your_username", "your_password");

PreparedStatement pstmt = conn.prepareStatement("UPDATE students SET age = ?


WHERE id = ?");

pstmt.setInt(1, newAge);

pstmt.setInt(2, id);

pstmt.executeUpdate();

out.println("Student updated successfully!");

pstmt.close();

conn.close();

%>

DeleteStudent.jsp (for Delete operation):

<%@ page import="java.sql.*" %>

<%

int id = Integer.parseInt(request.getParameter("id"));

Connection conn =
DriverManager.getConnection("jdbc:mysql://localhost/your_database_name",
"your_username", "your_password");

PreparedStatement pstmt = conn.prepareStatement("DELETE FROM students WHERE id =


?");

pstmt.setInt(1, id);

pstmt.executeUpdate();
out.println("Student deleted successfully!");

pstmt.close();

conn.close();

%>

You might also like