Next Gen File
Next Gen File
1 Create a webpage with HTML using paragraph and list tags 3/9/24
4 Create a simple JSP page. Separate the JSP and HTML 24/9/24
coding in different files and link them together.
Theory :
HTML (HyperText Markup Language) is the standard language used to create and
design webpages. The <p> tag is used to define paragraphs, while lists can be
created using the <ul> (unordered list) or <ol> (ordered list) tags, along with <li>
(list item) for individual entries.
Code :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Paragraphs and Lists</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
Output :
Welcome to My Webpage
Item 1
Item 2
Item 3
1. Step 1
2. Step 2
3. Step 3
Experiment - 2
Aim : Experiments based on PHP and MySQL to be implemented.
Steps:
Code :
Database Setup:
Run the following SQL query to create the database and table:
USE TestDB;
CREATE TABLE Users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL,
age INT NOT NULL
);
PHP Script:
When the PHP script is run, the following output is displayed in the browser:
Connected successfully
Users List:
Theory :
XML (Extensible Markup Language): A markup language used for storing
and transporting data. It is platform-independent and ensures data portability.
XSD (XML Schema Definition): Used to define the structure, data types,
and rules for an XML document.
XSLT (Extensible Stylesheet Language Transformations): A language
for transforming XML data into different formats (e.g., HTML, plain text).
Key Components:
Code :
XML document :
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>XML Fundamentals</title>
<author>John Doe</author>
<price>500</price>
<year>2021</year>
</book>
<book>
<title>Learning XSLT</title>
<author>Jane Smith</author>
<price>450</price>
<year>2020</year>
</book>
</library>
XML Schema :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="price" type="xs:decimal" />
<xs:element name="year" type="xs:gYear" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML stylesheet :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="library">
<xs:complexType>
<xs:sequence>
<xs:element name="book" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string" />
<xs:element name="author" type="xs:string" />
<xs:element name="price" type="xs:decimal" />
<xs:element name="year" type="xs:gYear" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output :
Library Collection
Theory :
· JSP (JavaServer Pages): A technology used to develop dynamic web pages by
embedding Java code within HTML using special JSP tags (<% %>).
· Separation of Concerns: Keeping JSP logic separate from HTML ensures better
maintainability and readability of code.
Code :
HTML file :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple JSP Example</title>
</head>
<body>
<h1>Welcome to the Simple JSP Example</h1>
<form action="process.jsp" method="post">
<label for="name">Enter your name:</label>
<input type="text" id="name" name="name" required><br><br>
<label for="age">Enter your age:</label>
<input type="number" id="age" name="age" required><br><br>
<button type="submit">Submit</button>
</form>
</body>
</html>
JSP file :
<%@ 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>Processed Data</title>
</head>
<body>
<h1>Processed Information</h1>
<%
// Retrieving data from the HTML form
String name = request.getParameter("name");
String age = request.getParameter("age");
1. Setup a Java Server: Use a web server like Apache Tomcat to deploy and
test JSP files.
2. File Placement:
1. Place index.html in the root directory of the web application.
2. Place process.jsp in the same directory or a subfolder.
3. Run the Application:
Input (HTML Page): The user submits their name and age through a form.
Output (JSP Page):
Hello, John!
Theory :
JDBC: A Java API for connecting and executing queries on a database.
ODBC: A standard API for accessing database management systems
(DBMS). JDBC-ODBC bridge is used to enable Java applications to interact
with ODBC-supported databases.
Code :
SQL for Database Setup (Example with a table named Employees):
salary DECIMAL(10, 2)
);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
if (connection != null) {
statement = connection.createStatement();
while (resultSet.next()) {
int id = resultSet.getInt("id");
resultSet.close();
} catch (ClassNotFoundException e) {
} catch (SQLException e) {
} finally {
try {
} catch (SQLException e) {
}}}
Steps to Run
Database Configuration:
Output :
Expected Output (if the table has data):
Employee Details:
Errors:
If the ODBC driver or data source is not set up correctly, the program throws an
error such as
Key Steps:
Code :
Database Setup (SQL Script) :
CREATE TABLE Users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
age INT
);
try {
// Step 1: Load the database driver
Class.forName("com.mysql.cj.jdbc.Driver");
out.println("<tr>");
out.println("<td>" + id + "</td>");
out.println("<td>" + name + "</td>");
out.println("<td>" + email + "</td>");
out.println("<td>" + age + "</td>");
out.println("</tr>");
}
} catch (Exception e) {
out.println("<p>Error: " + e.getMessage() + "</p>");
} finally {
// Step 5: Close the resources
try {
if (resultSet != null) resultSet.close();
if (statement != null) statement.close();
if (connection != null) connection.close();
} catch (SQLException e) {
out.println("<p>Error closing resources: " + e.getMessage() +
"</p>");
}
}
%>
</table>
</body>
</html>
1. Create the Users table using the SQL script provided above.
2. Insert some sample data.
A table displaying the user information from the database. For example:
Theory :
A Servlet is a Java program that runs on a web server or application server and acts
as a middle layer between the frontend (HTML) and backend (database or server
logic). It is used for handling HTTP requests, processing data, and generating
dynamic web content.
Lifecycle of a Servlet:
1. Initialization: The init() method is called when the Servlet is first loaded.
2. Request Handling: The service() method handles HTTP requests (usually
via doGet() or doPost() methods).
3. Termination: The destroy() method is called before the Servlet is removed
from memory.
Code :
Install and configure Apache Tomcat or any other Java-based web server.
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
<!DOCTYPE html>
<html>
<head><title>Servlet Response</title></head>
<body>
<h1>Hello, John!</h1>
<p>Welcome to the world of Servlets.</p>
</body>
</html>
Experiment - 8
Aim : Experiment based on Client Side Programming.
Theory :
Client-side programming is executed on the user's browser, making it fast and
responsive. Commonly used technologies include:
Code :
HTML, CSS, and JavaScript Example: Form Validation and Dynamic Content
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Client-Side Programming Example</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
form {
max-width: 300px;
margin: 0 auto;
}
input[type="text"], input[type="email"], button {
width: 100%;
padding: 10px;
margin: 10px 0;
}
.error {
color: red;
font-size: 0.9em;
}
.success {
color: green;
font-size: 1.1em;
}
</style>
</head>
<body>
<h1>Client-Side Programming Example</h1>
<form id="userForm">
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your
name">
<span id="nameError" class="error"></span>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your
email">
<span id="emailError" class="error"></span>
<script>
function validateForm() {
// Retrieve form values
const name = document.getElementById("name").value;
const email = document.getElementById("email").value;
const nameError = document.getElementById("nameError");
const emailError = document.getElementById("emailError");
const output = document.getElementById("output");
// Validate name
if (name.trim() === "") {
nameError.textContent = "Name is required.";
isValid = false;
}
// Validate email
if (!email.match(/^[^@\s]+@[^@\s]+\.[^@\s]+$/)) {
emailError.textContent = "Enter a valid email address.";
isValid = false;
}
Input Validation:
If the name field is empty, an error message will appear: "Name is required."
If an invalid email is entered, an error message will appear: "Enter a valid email
address."