Professional Documents
Culture Documents
Java Lab
Java Lab
1
1. SCRIPT SHOWING USE OF VARIABLES IN JAVASCRIPT
Aim:
Algorithm:
• Start the Program
• Declare the variables
• Print the variables
• Stop the program
Program :
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Variables</h1>
<p id="demo"></p>
<script>
const price1 = 5;
const price2 = 6;
</script>
</body>
</html>
2
OUTPUT:
JavaScript Variables
Result :
The above program executed the total number of given value.
3
2. SCRIPT SHOWING USE OF ARRAYS IN JAVASCRIPT
Aim:
Algorithm:
• Start the program
• Declare the variables
• find the length of array
• Print the array value
• Stop the program
Program :
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Arrays</h2>
<p id="demo"></p>
<script>
</script>
</body>
</html>
4
OUTPUT:
JavaScript Arrays
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>
function add(x,y)
return (x+y);
</script>
</head>
<body>
<script type="text/javascript">
var x=add(12,12);
</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=
</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>
function Confirmation()
if ( Val == true )
return true;
Else
{
return false;
</script>
10
</head>
<body>
<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>
<p id="demo"></p>
<script>
function myFunction()
document.getElementById("demo").innerHTML =
12
}
</script>
</body>
</html>
OUTPUT:
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>
<p id="demo"></p>
<script>
function my Function()
let text;
}
else
}
14
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
OUTPUT:
confirm () Method
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>
</head>
<body>
<tr>
</tr>
<tr>
</tr>
16
<tr>
</tr>
<tr>
<td>
</select>
</td>
</tr>
<tr>
</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:
<%
Cookie("last_name", request.getParameter("last_name"));
cookies.firstName.setMaxAge(60*60*24);
lastName.setMaxAge(60*60*24);
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>
<br />
</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 :
charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<html>
<head>
<title>Session In JSP</title>
</head>
<body>
<%
request.getSession(true);
session.setAttribute("name", name);
22
session.setAttribute("title", title);
java.util.Enumeration e =
session.getAttributeNames();out.println("Attributes
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