0% found this document useful (0 votes)
16 views24 pages

Nitin Gupta - WT - LABFILE

Uploaded by

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

Nitin Gupta - WT - LABFILE

Uploaded by

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

WEB Technology (KCS-652)

Internal Assessment
Name – Nitin Gupta
CSE AIML - 6th Sem. (2022-2025)
Roll No.- 2200291539004

Problems and Solutions

1. https://www.hackerrank.com/challenges/java-exception-handling-try-catch/problem

2. https://www.hackerrank.com/challenges/java-exception-handling/problem

3. https://www.hackerrank.com/challenges/java-inheritance-1/problem

4. https://www.hackerrank.com/challenges/java-abstract-class/problem

5. Write a program to create a portfolio using html and CSS

6. Write a Java program that throws an exception and catch it using a try-catch block.

7. Write a Java program to create a method that takes an integer as a parameter and throws an
exception if the number is odd.

8. Create a servlet to print username sent from html file

9. Write a program to print hit count of a server webpage

10. Create a servlet to take input and display Fibonacci series

11. Write a servlet program for servlet login and logout using cookies. Perform a
comparative analysis between Session and Cookies.

12. Write a Java program to create a method that reads a file and throws an exception if the file
is not found.

ANSWERS

ANS 1
ANS 2

ANS 3
ANS 4

5. Create a Portfolio Using HTML and CSS


6. Java Program with Try-Catch Block
7. Java Program with Exception for Odd Number

8. Servlet to Print Username from HTML File


9. Program to Print Hit Count of a Server Webpage
10. Servlet to Take Input and Display Fibonacci Series

ANS 11
ANS 12
Lab 1

https://www.geeksforgeeks.org/problems/kth-smallest-
element5635/1?page=1&sortBy=submissions

https://www.geeksforgeeks.org/problems/sum-of-digit-is-pallindrome-or-
not2751/1?itm_source=geeksforgeeks&itm_medium=article&itm_campaign=bottom_sticky_on_ar
ticle

https://www.geeksforgeeks.org/problems/need-some-change/1

https://www.geeksforgeeks.org/problems/rotate-array-by-n-elements-
1587115621/1?page=2&category=Arrays&sortBy=submissions

ANS 1
Ans 2

Ans 3
Ans 4
Lab 2

Write a Java program that throws an exception and catch it using a try-catch block.

Write a Java program to create a method that takes an integer as a parameter and throws an
exception if the number is odd.

Write a Java program to create a method that reads a file and throws an exception if the file is not
found.

Write a Java program that reads a list of integers from the user and throws an exception if any
numbers are duplicates.

Write a Java program to create a method that takes a string as input and throws an exception if the
string does not contain vowels.

1. Exception thrown and caught:

Java

public class ExceptionExample {

public static void main(String[] args) {

try {

throw new Exception("This is a test exception");

} catch (Exception e) {

System.out.println("An error occurred: " + e.getMessage());

2. Odd number check:


Java

public class OddNumberCheck {

public static void checkEven(int number) throws ValueError {

if (number % 2 != 0) {

throw new ValueError("The number is odd");

} else {

System.out.println(number + " is even");

public static void main(String[] args) {

try {

checkEven(3);

checkEven(8);

} catch (ValueError e) {

System.out.println("Error: " + e.getMessage());

3. File not found check (simulated):

Java

public class FileRead {

public static void openFile(String filename) throws FileNotFoundException {

try {

// Simulate reading the file

System.out.println("Reading file " + filename);

} catch (FileNotFoundException e) {

System.out.println("Error: " + e.getMessage());

}
}

public static void main(String[] args) {

try {

openFile("non-existent_file.txt"); // Replace with an actual non-existent filename

} catch (FileNotFoundException e) {

System.out.println("Error: " + e.getMessage());

4. Duplicate number check:

Java

public class DuplicateCheck {

public static void checkDuplicates(int[] numbers) throws ValueError {

try {

Set<Integer> seen = new

HashSet<>(); for (int num : numbers)

if (seen.contains(num)) {

throw new ValueError("Duplicate number found");

} else {

seen.add(num);

System.out.println("No duplicates found");

} catch (ValueError e) {

System.out.println("Error: " + e.getMessage());

public static void main(String[] args) {


try {

checkDuplicates(new int[]{1, 2, 3, 4, 2});

checkDuplicates(new int[]{5, 6, 7, 8});

} catch (ValueError e) {

System.out.println("Error: " + e.getMessage());

5. Vowel check:

Java

public class VowelCheck {

public static void checkVowels(String text) throws ValueError {

try {

String vowels = "aeiou";

boolean hasVowel =

false;

for (char ch : text.toLowerCase().toCharArray()) {

if (vowels.indexOf(ch) != -1) {

hasVowel = true;

break;

if (!hasVowel) {

throw new ValueError("Text does not contain vowels");

} else {

System.out.println("The text '" + text + "' contains vowels");

} catch (ValueError e) {

System.out.println("Error: " + e.getMessage());

}
public static void main(String[] args) {

try {

checkVowels("Hello world!");

checkVowels("hvnmmng");

} catch (ValueError e) {

System.out.println("Error: " + e.getMessage());

Lab 4
Problem Statement:

You are tasked with creating a simple online recipe book using HTML, CSS, XML, and JavaScript.
The recipe book should allow users to view recipes, add new recipes, and search for recipes based on
ingredients. Additionally, it should utilize dynamic HTML (DHTML) to enhance user interactions and
AJAX for asynchronous loading of recipe data.
Requirements:

HTML Basics:

Create a webpage layout for the recipe book, including headers, navigation menus, and content areas.
Implement HTML lists to display categories of recipes.
Use HTML tables to organize recipe details such as ingredients and instructions.
Incorporate images to visually represent each recipe.
Utilize frames or iframes to separate different sections of the webpage.
CSS Styling:

Apply CSS styles to HTML elements to improve the visual appearance of the recipe book.
Use CSS to define fonts, colors, margins, padding, and borders for various elements.
Implement CSS selectors to target specific elements for styling.
Ensure responsive design to adapt the layout for different screen sizes.

Dynamic HTML (DHTML):

Implement dynamic effects using JavaScript and CSS, such as hover effects on recipe images or
interactive buttons.
Use JavaScript to dynamically update content on the webpage without reloading the entire page.
Create interactive forms for adding new recipes or searching for recipes by ingredients.

XML Basics:

Define an XML schema for storing recipe data, including elements for recipe name, ingredients,
instructions, etc.
Use XML to represent recipe data in a structured format.
Apply XML namespaces and document type definition (DTD) to ensure data integrity and validation.

Scripting with JavaScript:

Integrate JavaScript to enhance user interactions, such as form validation and event handling.
Use JavaScript to parse and manipulate XML data, dynamically generating HTML content based on
the XML structure.
Implement AJAX requests to asynchronously load additional recipe data when users browse or search
for recipes.

Learning Objectives:

Design a user-friendly recipe book interface.

Utilize XML for structured recipe data storage.

Implement dynamic functionalities with JavaScript and AJAX.

Development Phases:
HTML and CSS:

Page Layout:

Create an HTML document with a clear structure using headers, navigation bar, and
content sections.

Implement HTML lists to categorize recipes (e.g., Appetizers, Main Courses, Desserts).

Use HTML tables to organize recipe details (ingredients with quantities, step-by-step instructions).

Include images for each recipe to enhance visual appeal. (Consider copyright or use free image
sources)

Styling:

Design CSS styles for improved visual presentation.

Define fonts, colors, margins, padding, and borders for different elements.

Utilize CSS selectors to target specific elements for styling (e.g., headers, lists, tables).

Ensure responsive design to adapt the layout for various screen sizes (mobile, desktop).

XML and Data Storage:

XML Schema:

Define an XML schema (XSD) for consistent recipe data structure.

Include elements for recipe name, ingredients (with quantity and unit), instructions (separate
steps), and optional elements like image URL, category, etc.

Recipe Data:

Create XML files with recipe data following the defined schema.

Consider storing these files on the server or locally within the web project structure.

JavaScript and Dynamic Features:

Interactivity:

Use JavaScript to enhance user experience with features like:

Hover effects on recipe images for a preview.

Interactive buttons (add to favorites, print recipe).

Implement forms for adding new recipes (using appropriate input fields).

Create a search functionality where users can search recipes by ingredients using a search bar.

XML Parsing:

Utilize JavaScript libraries like DOM (Document Object Model) or third-party libraries to parse the
XML data.

Extract recipe information from the XML based on element tags.


Dynamic Content:

Use JavaScript to dynamically generate HTML content based on the parsed XML data.

For example, populate a list of recipes on the main page or display the details of a specific recipe
when selected.

AJAX:

Implement AJAX requests to load recipe data asynchronously without full page reloads.

This can be used for faster navigation, searching, or loading detailed recipe information when a
user clicks on a recipe.

Additional Considerations:

Implement error handling and validation for user input and data retrieval.

Ensure proper organization of HTML, CSS, JavaScript, and XML files for maintainability.

Benefits of using this approach:

Structured Data: XML provides a clean and organized way to store recipe data.

Dynamic Updates: JavaScript and AJAX enable user interactions and dynamic content updates
without refreshing.

Separation of Concerns: HTML defines structure, CSS styles the appearance, and JavaScript adds
interactivity, promoting cleaner code.

By combining these technologies, you can create a user-friendly and interactive online recipe book,
offering a dynamic experience for users to explore and manage recipes.

Lab 7
Problem Statement:

You are tasked with developing a simple online student management system using Java Server Pages
(JSP) for dynamic web content generation. The student management system should allow
administrators to view, add, update, and delete student records. Additionally, it should utilize JSP
features such as implicit objects, scripting, standard actions, directives, and custom tag libraries for
efficient web development.

Requirements:

Introduction to JSP and Overview:

Create JSP pages to serve as the user interface for the student management system.
Understand the lifecycle of a JSP page and its role in generating dynamic content.

Implicit Objects, Scripting, and Standard Actions:

Utilize implicit objects such as request, response, session, and application to access and manipulate
HTTP request data.
Implement scripting elements (scriptlets, expressions, and declarations) to embed Java code within JSP
pages.
Use standard actions such as jsp:include, jsp:forward, and jsp:useBean for common tasks like
including other JSP pages, forwarding requests, and managing JavaBeans.

Directives and Custom Tag Libraries:

Explore JSP directives such as page, include, and taglib to define page-specific settings and include
external resources.
Define custom tag libraries to encapsulate reusable functionality and simplify complex operations
within JSP pages.

Conclusion and Final Projects:

Review all topics covered in the JSP module, including implicit objects, scripting, standard actions,
directives, and custom tag libraries.
Provide guidance and assistance for the final project, where students will develop a complete student
management system using JSP.
Conduct a presentation session where students showcase their projects and receive feedback from peers
and instructors.

Developing a Student Management System with JSP

This breakdown outlines the development process for a student management system using Java
Server Pages (JSP).

Learning Objectives:

Implement JSP for dynamic web content generation.

Manage student records (view, add, update, delete).


Utilize key JSP features for efficient development.

Development Phases:

Introduction and Overview:

Create JSP pages for the user interface (UI) with forms for data input.

Understand the JSP lifecycle: request processing, page translation, and response generation.

Implicit Objects, Scripting, and Standard Actions:

Leverage implicit objects like request, response, session, and application to access and manipulate
user data submitted through forms.

Utilize scripting elements within JSP pages:

Scriptlets: Embed Java code blocks for complex logic (<% ... %>).

Expressions: Directly print Java code results (<%= ... %>).

Declarations: Declare variables within the JSP page (<%! ... %>).

Implement standard actions to simplify tasks:

jsp:include: Include content from another JSP page.

jsp:forward: Redirect requests to another JSP page.

jsp:useBean: Manage JavaBeans (reusable components) within the page.

Directives and Custom Tag Libraries:

Explore JSP directives to define page-specific settings:

<%@ page ... %>: Set page attributes like content type, error handling.

<%@ include ... %>: Include external files like headers or footers.

<%@ taglib ... %>: Define custom tag libraries for reusability.

Develop custom tag libraries to encapsulate frequently used functionalities, improving code
organization and maintainability.

Conclusion and Final Project:

Review all covered topics for a comprehensive understanding of JSP development.

Develop a complete student management system as a final project, utilizing the learned concepts:

View student records in a table format.

Implement forms for adding, updating, and deleting students.

Validate user input and handle potential errors.

Connect to a database (e.g., MySQL) to store and retrieve student information.

Present your project to peers and instructors for feedback and evaluation.
Problem Statement:

You are tasked with developing a simple online bookstore application using Java Servlets and JDBC for
database connectivity. The bookstore application should allow users to browse books, add them to their
cart, and proceed to checkout. Additionally, it should utilize JDBC to retrieve book data from a
database, handle transactions during checkout, and use servlets for session management.

Requirements:

JDBC Basics:

Establish a database connection using JDBC and retrieve book data from a database table.
Implement SQL queries to merge data from multiple tables using JOIN operations.
Handle transaction processing during checkout, ensuring atomicity and consistency of database
operations.
Utilize stored procedures to encapsulate complex database operations, such as updating inventory levels
after a purchase.

Servlets:

Define servlets to handle different stages of the bookstore application, such as browsing books, adding
to cart, and checkout.
Understand the servlet life cycle and implement methods to handle HTTP requests, such as doGet() and
doPost().
Implement session tracking mechanisms using Cookies and HttpSession to maintain user sessions
across multiple requests.

Lab 5

Building an Online Bookstore with Java Servlets and JDBC

Here's a breakdown of developing a simple online bookstore application using Java Servlets and
JDBC:

Learning Objectives:

Implement JDBC for database connectivity and data retrieval.

Manage book browsing, cart functionality, and checkout process.

Utilize servlets for request handling and session management.


Development Phases:

JDBC Basics:

Database Setup:

Create a database (e.g., MySQL) with tables for books (title, author, price, etc.) and potentially
another for user information (optional).

JDBC Connectivity:

Establish a connection pool for efficient database access.

Utilize JDBC classes to connect, execute queries, and retrieve data.

Data Retrieval:

Write SQL queries to fetch book data from the database table.

Implement JOIN operations to retrieve data from multiple tables (e.g., join books with categories).

Transactions:

Understand the ACID (Atomicity, Consistency, Isolation, Durability) properties of transactions.

Utilize JDBC Connection.setAutoCommit(false) and commit()/rollback() methods to manage


transactions during checkout (updating cart items and inventory).

Stored Procedures (Optional):

Create stored procedures in the database to encapsulate complex operations like updating
inventory after a purchase.

Call stored procedures from your Java code using JDBC.

Servlets:

Servlet Creation:

Develop servlets for different functionalities:

BrowseBooksServlet: Display available books.

AddToCartServlet: Handle adding books to the user's cart.

ViewCartServlet: Display the user's cart contents.

CheckoutServlet: Process checkout, handle transactions, and update

database. Servlet Lifecycle:

Understand the servlet lifecycle (init, service, destroy) and implement corresponding methods.

Request Handling:

Implement doGet() and doPost() methods to handle HTTP GET and POST requests from the user.

Extract request parameters (e.g., book ID for adding to cart).

Session Management:
Utilize HttpSession to maintain user sessions across multiple requests.

Store cart items and user information (if applicable) in the session object.

Consider using cookies as an alternative or in conjunction with sessions for specific scenarios.

Additional Considerations:

Implement security measures to prevent unauthorized access and protect user data.

Design a user-friendly interface (HTML forms, CSS for styling) for user interaction with the
bookstore application.

Error handling should be implemented to gracefully manage potential exceptions during database
operations or user input validation.

Benefits of using Servlets and JDBC:

Server-side Processing: Servlets allow for robust and secure processing of user requests and
database interactions.

Database Connectivity: JDBC provides a standard way to connect and interact with various
databases.

Scalability: Servlets are scalable and can handle a high volume of users with efficient session
management.

By following these steps and incorporating best practices, you can develop a functional online
bookstore application leveraging Java Servlets and JDBC. Remember, this is a general outline,
and specific implementation details will depend on your chosen database schema, chosen UI
framework, and desired security features.

You might also like