JAVA SCRIPT
Experiment 1: JavaScript Basics
Title: Variables, Data Types and Operators
Objective:
To understand variables, operators, and data types in JavaScript.
Input:
Values of variables.
Code:
<script>
let a = 10;
let b = 5;
let sum = a + b;
[Link]("Sum:", sum);
</script>
OUTPUT
Sum: 15
Experiment 2: Conditional Statements
Title: If-Else and Switch
Objective:
To implement decision-making statements.
Input:
User input number.
Code:
<script>
let n = 10;
if(n % 2 == 0){
[Link]("Even");
} else {
[Link]("Odd");
switch(n){
case 10:
[Link]("Number is 10");
break;
default:
[Link]("Other number");
</script>
Output:
Even
Number is 10
Experiment 3: Loops
Title: Looping in JavaScript
Objective:
To use loops and break statement.
Input:
Loop range.
Code:
<script>
for(let i=1; i<=5; i++){
if(i == 3) break;
[Link](i);
</script>
Output:
Experiment 4: Functions
Title: JavaScript Functions
Objective:
To create and call functions.
Input:
Function parameters.
Code:
<script>
function add(a, b){
return a + b;
[Link](add(2,3));
</script>
Output:
Experiment 5: Objects and Events
Title: Objects and Event Handling
Objective:
To use objects and handle events.
Input:
Button click.
Code:
<button onclick="show()">Click</button>
<script>
function show(){
let student = {name:"John", age:20};
alert([Link]);
</script>
Output:
Alert box displaying: John
CGI SCRIPT
Experiment 6: CGI GET Method
Title: Handling GET Request
Objective:
To process form data using GET method.
Input:
Form data.
Code (Python CGI):
#!/usr/bin/python3
import cgi
form = [Link]()
name = [Link]("name")
print("Content-type:text/html\n")
print("<h1>Hello", name, "</h1>")
Output:
Displays: Hello <name>
Experiment 7: CGI POST Method
Title: Handling POST Request
Objective:
To process form data using POST method.
Input:
User form input.
Code: (same as GET but method="POST" in HTML form)
<form method="POST" action="[Link]">
<input type="text" name="name">
<input type="submit">
</form>
Output:
Displays submitted data.
JAVA SERVLET
Experiment 8: Servlet Life Cycle
Title: Basic Servlet Program
Objective:
To understand servlet lifecycle.
Input:
Client request.
Code:
import [Link].*;
import [Link].*;
import [Link].*;
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
[Link]("text/html");
PrintWriter out = [Link]();
[Link]("<h1>Hello Servlet</h1>");
Output:
Webpage showing: Hello Servlet
Experiment 9: doPost Method
Title: Handling POST in Servlet
Objective:
To handle POST requests.
Code:
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {
String name = [Link]("name");
[Link]().println("Hello " + name);
Output:
Displays submitted name.
Experiment 10: Cookies and Session
Title: Session Tracking
Objective:
To manage user sessions.
Code:
Cookie c = new Cookie("user","John");
[Link](c);
Output:
Cookie stored in browser.
JSP (Java Server Pages)
Experiment 11: JSP Basics
Title: JSP Scriptlet
Objective:
To use scriptlet tag.
Code:
<html>
<body>
<%
[Link]("Hello JSP");
%>
</body>
</html>
Output:
Displays: Hello JSP
Experiment 12: JSP Implicit Objects
Title: Request and Response
Objective:
To use implicit objects.
Code:
<%
String name = [Link]("name");
[Link]("Hello " + name);
%>
Output:
Displays user input.
Experiment 13: JSP Directive
Title: Include Directive
Objective:
To include files in JSP.
Code:
<%@ include file="[Link]" %>
Output:
Includes another JSP file.
Experiment 14: JSP Action Tags
Title: Forward and Include
Objective:
To use JSP action tags.
Code:
<jsp:forward page="[Link]"/>
Output:
Page redirected.
Experiment 15: JavaBean in JSP
Title: Using JavaBean
Objective:
To integrate JavaBean.
Code:
<jsp:useBean id="obj" class="Student"/>
Output:
Bean object created.
JDBC
Experiment 16: JDBC Connection
Title: Database Connectivity
Objective:
To connect Java with database.
Input:
DB credentials.
Code:
import [Link].*;
class Test {
public static void main(String args[]) throws Exception {
Connection con = [Link](
"jdbc:mysql://localhost:3306/test","root","");
[Link]("Connected");
Output:
Connected
Experiment 17: Prepared Statement
Title: Insert Data using PreparedStatement
Objective:
To insert data securely.
Code:
PreparedStatement ps = [Link](
"insert into student values(?,?)");
[Link](1,1);
[Link](2,"John");
[Link]();
Output:
Data inserted into table.
Experiment 18: Callable Statement
Title: Call Stored Procedure
Objective:
To execute stored procedure.
Code:
CallableStatement cs = [Link]("{call myproc()}");
[Link]();
Output:
Procedure executed successfully.