0% found this document useful (0 votes)
19 views

Java Lab

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

Java Lab

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

CONTENT

S No Advanced Java Programming Page


No
Tittle

1 Script showing use of variables in JavaScript 2

2 Script showing use of arrays in JavaScript 4

3 Script showing user defined functions 6

4 Script showing how JavaScript places code in the browser window 8

5 Script showing use of alert dialog box 10

6 Script showing use of prompt dialog box 12

7 Script showing use of Confirm dialog box 14

8 Program showing JavaScript front-end validation 16

9 Program implementing the concept of cookies in JSP 19

10 Program implementing the concept of session in JSP 22

1
1. SCRIPT SHOWING USE OF VARIABLES IN JAVASCRIPT

Aim:

To this program execute script use of variables in java script

Algorithm:
• Start the Program
• Declare the variables
• Print the variables
• Stop the program

Program :

<!DOCTYPE html>

<html>

<body>

<h1>JavaScript Variables</h1>

<p>In this example, price, price2, and total are variables.</p>

<p id="demo"></p>

<script>

const price1 = 5;

const price2 = 6;

let total = price1 + price2; document.getElementById("demo").innerHTML =

"The total is:” + total;

</script>

</body>

</html>

2
OUTPUT:

JavaScript Variables

In this example, price, price2, and total are

variables.The total is: 11

Result :
The above program executed the total number of given value.

3
2. SCRIPT SHOWING USE OF ARRAYS IN JAVASCRIPT

Aim:

To this program show use of arrays in javascript

Algorithm:
• Start the program
• Declare the variables
• find the length of array
• Print the array value
• Stop the program

Program :

The length Property

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Arrays</h2>

<p>The length property returns the length of an array.</p>

<p id="demo"></p>

<script>

const fruits = ["Banana", "Orange", "Apple", "Mango"];

Document. get Element By Id ("demo").inner HTML = fruits. length;

</script>

</body>

</html>

4
OUTPUT:

JavaScript Arrays

The length property returns the length of an

array.4

Result:
The above program executed successfully to show the value of arrays

5
3. SCRIPT SHOWING USER DEFINED FUNCTIONS

Aim:
To this program to show the user defined functions

Algorithm:
• Start the program
• Declare the variables and user_defined functions
• execute the functions
• Print the functions and variables
• Stop the program

Program:
<html>

<head>

<title>Write your title here </title>


<scripttype="text/javascript" >

function add(x,y)

return (x+y);

</script>

</head>

<body>

<script type="text/javascript">

var x=add(12,12);

document.write("Addition is " + x);

</script>

</body>

</html>

6
OUTPUT:

Addition is 24

Result:
The above program executed successfully to show the add of two value of arrays

7
4. SCRIPT SHOWING HOW JAVASCRIPT
PLACES CODE IN THE BROWSER WINDOW

Aim:
To this program to show the code in browser window

Algorithm:
• Start the program
• Declare the variables functions
• Run the program
• It show the current window size
• Stop the program

Program:

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Window</h2>

<p id="demo"></p>

<script>

document.getElementById("demo").innerHTM

L=

"Browser inner window width: " + window.innerWidth + "px<br>"

+"Browser inner window height: " + window.innerHeight + "px";

</script>

</body>

</html>

8
OUTPUT:

JavaScript Window

Browser inner window width: 607px Browser inner window height: 556px

Result:
To above this program executed the current window size.

9
5. SCRIPT SHOWING USE OF ALERT DIALOG BOX

Aim:
To show the alert message with dialog box

Algorithm:
• Start the program
• Declare the variable and functions
• Run the program
• Display the output with dialogbox
• Stop the program

Program :

<!DOCTYPE html>

<html>

<head>

<script type="text/java script">

function Confirmation()

var Val = confirm("Do you want to continue ?");

if ( Val == true )

document.write (" CONTINUED!");

return true;

Else
{

document.write ("NOT CONTINUED!");

return false;

</script>

10
</head>

<body>

<p>Click me: </p>

<form>
<input type="button" value="Click Me"

Onclick="Confirmation()" >

</form>

</body>

</html>

OUTPUT:

Result:
To above this program executed successfully with dialog box .

11
6. SCRIPT SHOWING USE OF PROMPT DIALOG BOX

Aim:
To this program use to prompt dialog box.

Algorithm:
• Start the program
• Declare the variable and functions
• Run the program
• Print the statements
• Stop the program

Program :

<!DOCTYPE html>

<html>

<body>

<h1>The Window Object</h1>

<h2>The prompt() Method</h2>

<p>Click the button to demonstrate the prompt box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>

function myFunction()

let person = prompt("Please enter your name", "Harry

Potter");if (person != null)

document.getElementById("demo").innerHTML =

"Hello " + person + "! How are you today?";

12
}

</script>

</body>

</html>

OUTPUT:

The Window Object

The prompt() Method

Click the button to demonstrate the prompt box.

Result:
The above program is use to prompt the dialog box.

13
7. SCRIPT SHOWING USE OF CONFIRM DIALOG BOX

Aim:
To this program use of confirm dialog box.

Algorithm:
• Start the program
• Declare the variable and functions
• Run the program
• Print the statements
• Stop the program

Program :

<!DOCTYPE html>

<html>

<body>

<h1>The Window Object</h1>

<h2>The confirm() Method</h2

<p>Click the button to display a confirm box.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>

function my Function()

let text;

if (confirm("Press a button!") == true)

text = "You pressed OK!";

}
else

text = "You canceled!";

}
14
document.getElementById("demo").innerHTML = text;

</script>

</body>

</html>

OUTPUT:

The Window Object The

confirm () Method

Click the button to display a


confirm box.

Result:
To this program swap the numbers using function templates.

15
8. PROGRAM SHOWING JAVASCRIPT FRONT-END VALIDATION

Aim:
To this program show java script Front-End Validation

Algorithm:
• Start the program
• Declare the variable and functions
• Create the table with options
• Run the program
• Print the table and functions
• Stop the program

Program :
<html>

<head>

<title>Form Validation</title>

<script type = "text/javascript">

<!--

// Form validation code will come here.

//-->

</script>

</head>

<body>

<form action = "/cgi-bin/test.cgi" name = "myForm" onsubmit = "return(validate());">

<table cellspacing = "2" cellpadding = "2" border = "1">

<tr>

<td align = "right">Name</td>

<td><input type = "text" name = "Name" /></td>

</tr>

<tr>

<td align = "right">EMail</td>

<td><input type = "text" name = "EMail" /></td>

</tr>

16
<tr>

<td align = "right">Zip Code</td>

<td><input type = "text" name = "Zip" /></td>

</tr>

<tr>

<td align = "right">Country</td>

<td>

<select name = "Country">

<option value = "-1" selected>[choose yours]</option>

<option value = "1">USA</option>

<option value = "2">UK</option>

<option value = "3">INDIA</option>

</select>

</td>

</tr>

<tr>

<td align = "right"></td>

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

</tr>

</table>

</form>

</body>

</html>

17
OUTPUT:

Result :
To this program display the show java script Front-End Validation

18
9. PROGRAM IMPLEMENTING THE CONCEPT OF COOKIES IN JSP

Aim:
To program implementing the concept of cookies in jsp.

Algorithm:
• Start the program
• Declare the variable and functions
• Enter the cookie function and html tags
• Run the program
• Print the table and functions
• Stop the program

Program:

<%

// Create cookies for first and last names.

Cookie firstName = new Cookie("first_name",

request.getParameter("first_name"));Cookie lastName = new

Cookie("last_name", request.getParameter("last_name"));

// Set expiry date after 24 Hrs for both the

cookies.firstName.setMaxAge(60*60*24);

lastName.setMaxAge(60*60*24);

// Add both the cookies in the response

header.response.addCookie( firstName );

response.addCookie( lastName );

%>

<html>

<head>

<title>Setting Cookies</title>
19
</head>

<body>

<center>

<h1>Setting Cookies</h1>

</center>

<ul>

<li><p><b>First Name:</b>

<%= request.getParameter("first_name")%>

</p></li>

<li><p><b>Last Name:</b>

<%= request.getParameter("last_name")%>

</p></li>

</ul>

</body>

</html>

Let us put the above code in main.jsp file and use it in the following
HTMLpage −

<html>

<body>

<form action = "main.jsp" method = "GET">

First Name: <input type = "text" name = "first_name">

<br />

Last Name: <input type = "text" name = "last_name" />

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

</form>

</body>

</html>

20
OUTPUT:

First

Name:

Last

Name:

Submit

Result:
This program execute successfully to implementing the concept of cookies in jsp.

21
10.PROGRAM IMPLEMENTING THE CONCEPT OF SESSION IN JSP

Aim:
To program implementing the concept of session in jsp.

Algorithm:
• Start the program
• Declare the variable and functions
• Enter the cookie function and html tags
• Run the program
• Print the table and functions
• Stop the program

Program :

<%@ page language="java" contentType="text/html;

charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>

<!DOCTYPE html >

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>Session In JSP</title>

</head>

<body>

<%

request.getSession(true);

out.println("Is Session New : "+session.isNew());

out.println("Session Creation Time :

"+session.getCreationTime());Object name = "Raju";

Object title = "Singh";

session.setAttribute("name", name);

22
session.setAttribute("title", title);

out.println("Name = "+ session.getAttribute("name"));

out.println("Title = "+ session.getAttribute("title"));

java.util.Enumeration e =

session.getAttributeNames();out.println("Attributes

Are : "); while(e.hasMoreElements())

out.println(e.nextElement());

session.invalidate();

%>

</body>

</html>

OUTPUT:

Result:
This program execute successfully to the program
implementing the concept of session in jsp.

23

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy