0% found this document useful (0 votes)
12 views29 pages

Lab Assignment 2

The document contains answers to various lab assignments covering HTML, XML, JavaScript, Angular, and Servlets. It includes explanations of HTML tags, multimedia embedding, JavaScript validation, and the Servlet life cycle, among other topics. Each section provides concise information and examples relevant to web development and programming concepts.

Uploaded by

Aditya Barve
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)
12 views29 pages

Lab Assignment 2

The document contains answers to various lab assignments covering HTML, XML, JavaScript, Angular, and Servlets. It includes explanations of HTML tags, multimedia embedding, JavaScript validation, and the Servlet life cycle, among other topics. Each section provides concise information and examples relevant to web development and programming concepts.

Uploaded by

Aditya Barve
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/ 29

Lab Assignment 2

Here are the answers to the questions from the image:

1. While creating a website, how many tags can you use? List them with explanation.
There are many HTML tags, some important ones include:

• <html>: Root element of the HTML document.

• <head>: Contains meta-information, title, and links to styles/scripts.

• <body>: Contains the content of the webpage.

• <h1> to <h6>: Headings tags from largest to smallest.

• <p>: Paragraph tag.

• <a>: Anchor tag used for hyperlinks.

• <img>: Used to embed images.

• <ul>, <ol>, <li>: Unordered and ordered lists.

• <div>: Division, used for layout.

• <span>: Inline container for styling.

• <form>: For input forms.

• <input>, <textarea>, <button>: Form elements.

• <table>, <tr>, <td>, <th>: For tables.

2. How can we insert object/embed concept in our website?


You can use:

• <embed>: Embeds external content like PDFs, videos.

• <object>: Used to embed multimedia, webpages, etc.

• <iframe>: Embeds another HTML page within a page.


Example:

<embed src="file.pdf" width="600" height="500">

<object data="movie.mp4" type="video/mp4"></object>

<iframe src="https://example.com" width="600" height="400"></iframe>

3. What are the ways to import multimedia resources to our website?

• <img>: For images.


• <audio>: For sound/music.

• <video>: For video files.

• <embed>, <object>, <iframe>: For other multimedia resources.

• External resources via links or APIs.

4. What is the use of iframe tag in website?


The <iframe> tag is used to embed another HTML document within the current document.
Example use cases:

• Embedding YouTube videos

• Embedding Google Maps

• Loading external websites inside your page

5. Which type of attribute is used to implement JavaScript concept to HTML code?

• Event attributes are used:

o onclick, onmouseover, onchange, onload, etc.


Example:

<button onclick="alert('Hello')">Click Me</button>

6. How many platforms are available to write down HTML code? Which one is better? Explain in
brief.
Platforms:

• Text editors: Notepad, Notepad++

• Code editors: VS Code, Sublime Text, Atom

• IDEs: WebStorm, Brackets

• Online platforms: CodePen, JSFiddle, Repl.it


Best: VS Code – it offers extensions, auto-completion, live server, and is lightweight.

7. In List tags there is <DD>, <DT>... Tags are available. Why are they used during making of
website?
These are used in Definition Lists:

• <dl>: Defines a definition list

• <dt>: Definition term

• <dd>: Definition description


Example:
<dl>

<dt>HTML</dt>

<dd>HyperText Markup Language</dd>

</dl>

8. Can we implement <blockquote> tag to make Restaurant website? What is the purpose of
<fieldset> and <legend> tags?

• Yes, <blockquote> is used to display customer reviews/testimonials.

• <fieldset>: Groups related elements in a form.

• <legend>: Provides a caption/title for the <fieldset>.


Example:

<fieldset>

<legend>Reservation Details</legend>

<input type="text" placeholder="Name">

</fieldset>

9. What are the technologies available in client-side for web application development?

• HTML: Structure

• CSS: Styling

• JavaScript: Logic & interaction

• Frameworks/Libraries: React, Angular, Vue.js

• AJAX: For asynchronous data loading

• Bootstrap, Tailwind CSS: UI frameworks

10. What are the rules for cascading style sheet to implement inheritance concept?
CSS Inheritance rules:

• Some properties (like font, color) are inherited by default.

• Use of inherit, initial, unset values:

o inherit: Forces inheritance

o initial: Resets to default value

o unset: Acts as either inherit or initial


Example:
div {

color: inherit;

Let me know if you want these answers in a printable format (Word or PDF).

Lab Assignment 3
Here are the answers to your XML Lab Assignment – 3 questions:

1. What is meant by XML document? How can we store data with the help of XML language?
XML (Extensible Markup Language) is a markup language designed to store and transport data. It is
both human-readable and machine-readable.
Data is stored using custom tags that define structure and meaning:

<student>

<name>John</name>

<age>22</age>

</student>

You can store data in a hierarchical format and use it in web services, configuration files, etc.

2. What is a DTD file? How many types are present in DTD file?
DTD (Document Type Definition) defines the structure and legal elements/attributes in an XML
document.
Types:

• Internal DTD – defined within the XML file.

• External DTD – defined in a separate .dtd file.


Example (Internal):

<!DOCTYPE student [

<!ELEMENT student (name, age)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT age (#PCDATA)>

]>

3. What is the purpose of XSD where we are already using DTD?


XSD (XML Schema Definition) is a more powerful and precise alternative to DTD.
Purpose:
• Defines data types (e.g., integer, date)

• Supports namespaces

• Written in XML syntax

• More extensible and widely used in modern XML documents.

4. How are XSL files used to perform programming?


XSL (Extensible Stylesheet Language) is used to transform and present XML data.
It includes:

• XSLT – for transforming XML into HTML or another XML.

• XPath – to navigate XML nodes.

• XSL-FO – for formatting.


Example:

<xsl:template match="/student">

<h2><xsl:value-of select="name"/></h2>

</xsl:template>

5. Write down syntax of schema – i.e., XML building blocks.


Key elements:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="student" type="xs:string"/>

<xs:element name="age" type="xs:integer"/>

</xs:schema>

Building blocks:

• <xs:element>

• <xs:complexType>

• <xs:sequence>

• <xs:attribute>

6. What are the rules designed for XML document?

• Must have a root element.

• Tags must be properly nested and closed.

• Case-sensitive.
• Attribute values must be quoted.

• Only one root element is allowed.

7. Explain tags related to XML including attributes, entities like #PCDATA and CDATA.

• Attributes: Provide additional info about elements.

<student id="101">John</student>

• #PCDATA: Parsed Character Data – text that will be parsed by XML parser.

• CDATA: Character Data – blocks of text not parsed by the parser.

<![CDATA[ <message>Hello</message> ]]>

8. Difference between XML Schema and DTD.

Feature DTD XSD

Syntax Not XML XML-based

Data Types Limited Strongly typed

Namespaces Not supported Supported

Validation Less strict More precise

9. Explain the concept of XML namespaces.


Namespaces avoid element name conflicts by qualifying names with a URI.

<book xmlns:ns1="http://example.com/ns1">

<ns1:title>XML Guide</ns1:title>

</book>

Useful when combining XML from different sources.

10. How XML processing works when the data is based on DOM?
DOM (Document Object Model) represents XML as a tree structure.

• Parser reads XML and builds DOM tree.

• Allows programmatic access to nodes using JavaScript or other languages.

• Example using JS:

let title = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;


11. Explain how Ajax works? List out step-by-step working process of Ajax.
AJAX (Asynchronous JavaScript and XML) allows data loading without refreshing the page.
Steps:

1. Create an XMLHttpRequest object

2. Send request to server

3. Server processes the request

4. Response is sent back

5. JavaScript updates the webpage without reload


Example:

let xhr = new XMLHttpRequest();

xhr.open("GET", "data.xml", true);

xhr.onreadystatechange = function() {

if (xhr.readyState == 4 && xhr.status == 200) {

document.getElementById("result").innerHTML = xhr.responseText;

};

xhr.send();

Let me know if you’d like this in a formatted PDF or document!

Lab Assignment 4
Here are the answers to your JavaScript and Angular questions from the image:

1. What is the role of validation in JavaScript? List and explain types of JavaScript validation.

Role of Validation: Ensures that the user provides correct and complete input before form
submission.

Types of Validation:

• Client-side Validation: Performed in browser using JavaScript before data is sent to the
server.

• Server-side Validation: Done on the server after submission.

• Examples:

o Required fields

o Format (e.g., email, phone number)


o Length (e.g., password must be 8+ characters)

2. What is the use of prompt and alert?

• alert(): Displays a simple message in a dialog box.

• alert("Welcome!");

• prompt(): Asks user for input via a dialog box.

• let name = prompt("Enter your name:");

3. How many types are there to write output in JavaScript?

Ways to write output:

1. document.write() – writes directly to the HTML document.

2. alert() – shows output in a popup.

3. console.log() – outputs to the browser’s console.

4. innerHTML – inserts output into a specific HTML element.

4. List out and explain HTML DOM events.

DOM Events trigger actions in JS:

• onclick – when an element is clicked.

• onmouseover – when mouse hovers.

• onkeydown – when a key is pressed.

• onload – when page finishes loading.

• onsubmit – when a form is submitted.

5. What is the purpose of JavaScript objects? Define & display JavaScript object. Create JSON
object.

Purpose: JS objects are used to store keyed collections of data.

Example JS Object:

let student = {

name: "John",

age: 21

};
console.log(student.name);

JSON Object:

"name": "John",

"age": 21

6. Why is JavaScript used in Angular? Explain modules in Angular with respect to directives.

• JavaScript forms the base of Angular (which uses TypeScript, a superset of JS).

• Used for: data binding, event handling, API calls.

Angular Modules:

• @NgModule organizes components, directives, pipes.

• Directives in Angular are:

o Structural (e.g., *ngIf, *ngFor)

o Attribute (e.g., ngClass, ngStyle)

7. How can we create a project in Angular?

Steps:

1. Install Angular CLI:

2. npm install -g @angular/cli

3. Create project:

4. ng new project-name

5. Serve it:

6. cd project-name

7. ng serve

8. What is the process of data binding in Angular?

Data Binding connects component logic with UI.

Types:

1. Interpolation: {{ data }}

2. Property Binding: [value]="data"


3. Event Binding: (click)="function()"

4. Two-way Binding: [(ngModel)]="data"

9. button:active {} – Explain this property.

• The :active pseudo-class applies styles when an element is being activated (e.g., clicked).

Example:

button:active {

background-color: blue;

color: white;

Effect: Changes button color while being clicked.

Let me know if you want all answers compiled into a formatted PDF or document

Lab Assignment 5
Sure! Let's go into detailed explanation for each of the 10 questions from the Servlet assignment.
These answers are helpful for your Viva, practicals, or assignments.

1. What is Servlet? How can we connect a database to Servlet?

A Servlet is a Java class that handles HTTP requests and generates responses. It runs on a Servlet
container (like Apache Tomcat) and is used to create dynamic web applications.

Connecting to a Database (MySQL)

1. Load JDBC Driver:

2. Class.forName("com.mysql.cj.jdbc.Driver");

3. Establish Connection:

4. Connection con = DriverManager.getConnection(

5. "jdbc:mysql://localhost:3306/db_name", "username", "password");

6. Perform SQL operations using Statement or PreparedStatement.

7. Close connection.

2. Explain step-by-step process of Table creation with MySQL.

Steps to create a table:


1. Login to MySQL:

2. mysql -u root -p

3. Create Database:

4. CREATE DATABASE college;

5. Use the Database:

6. USE college;

7. Create Table:

8. CREATE TABLE students (

9. roll_no INT PRIMARY KEY,

10. name VARCHAR(100),

11. age INT,

12. department VARCHAR(50)

13. );

14. View Table:

15. DESC students;

3. How can we fetch data on browser with Java & MySQL?

Using a Servlet to fetch data and display it in HTML.

Example:

Connection con = DriverManager.getConnection(...);

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT * FROM students");

while(rs.next()) {

out.println("<p>" + rs.getString("name") + "</p>");

• This will output each student's name on the browser as HTML.

4. What is Server-Side and Client-Side Technology?


Type Definition Examples

Client-side Runs in the browser, interacts with users HTML, CSS, JavaScript

Server-side Runs on the server, handles logic/database Java Servlets, PHP, Node.js

5. Which server is mostly used in Servlets to connect database?

Apache Tomcat is most commonly used.

• It supports Java Servlets and JSP.

• Acts as a Servlet Container.

• Works with databases like MySQL using JDBC API.

6. Draw and Explain Servlet Life Cycle

There are 3 main stages:

1. init() – Called once when servlet is loaded. Used for initialization.

2. service() – Called every time when a request comes. Handles logic.

3. destroy() – Called once when the servlet is unloaded (server shutdown or redeploy).

Life Cycle Diagram:

Client ---> Servlet Container ---> init()

---> service()

---> destroy()

7. Methods to Send Request and Get Response in Servlet

HTTP Servlet Methods:

• doGet() – handles GET request

• doPost() – handles POST request

Example:

protected void doGet(HttpServletRequest request, HttpServletResponse response) {

String name = request.getParameter("name");

response.getWriter().println("Hello " + name);

}
8. Which query is executed in servlet to show table?

You can use:

SELECT * FROM tablename;

Servlet Code:

ResultSet rs = stmt.executeQuery("SELECT * FROM students");

while(rs.next()) {

out.println(rs.getString("name"));

9. What is the purpose of web.xml file in Servlet?

web.xml is the deployment descriptor of a web application.

It is used to:

• Configure servlets

• Map URLs to servlets

• Set welcome file, error pages

Example:

<servlet>

<servlet-name>Login</servlet-name>

<servlet-class>com.LoginServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>Login</servlet-name>

<url-pattern>/login</url-pattern>

</servlet-mapping>

10. Why do we need servlet-api.jar file?

The servlet-api.jar contains core servlet classes like:

• HttpServlet

• HttpServletRequest

• HttpServletResponse

It is needed:
• During compilation in IDE or CLI

• It is not part of the standard Java SE library

• It is provided by servlet containers (e.g., Tomcat)

To add it:

• In Eclipse/IDEA, right-click → Build Path → Add External JAR → select servlet-api.jar

Would you like me to compile all these answers into a Word or PDF file?

Lab Assignment 6

Here's a detailed explanation of each question from Lab Assignment 6 (JSP):

1. What is the use of JSP where we have already Java Servlet?

• Answer: JSP (JavaServer Pages) is a technology that helps in creating dynamic web content.
Unlike Servlets, which are pure Java code, JSP allows embedding HTML with Java code,
making it easier to design web pages. JSP is mostly used for the presentation layer, while
Servlets are better for the business logic.

2. Is it possible to create web applications with help of JSP?

• Answer: Yes, it is possible. JSP can be used to create the front-end (view) of web
applications. Combined with Servlets or JavaBeans, JSP can also handle backend processing,
form handling, session management, and database operations.

3. Explain JSP page lifecycle?

• Answer:

1. Translation – JSP is converted into a Servlet by the container.

2. Compilation – The translated Servlet is compiled.

3. Instantiation – The Servlet class is instantiated.

4. Initialization – jspInit() method is called once.

5. Request Processing – jspService() is called for every request.

6. Destruction – jspDestroy() is called before destroying the instance.


4. What are the scripting elements used in JSP?

• Answer:

o Declarations (<%! %>) – Declare variables/methods.

o Scriptlets (<% %>) – Write Java code inside HTML.

o Expressions (<%= %>) – Output Java values directly to the client.

5. What is meant by JSTL?

• Answer: JSTL (JavaServer Pages Standard Tag Library) is a collection of useful tags for
common tasks like iteration, conditionals, formatting, and SQL operations. It removes the
need to write Java code in JSP and promotes cleaner code.

6. How can we run JSP applications? Why the need of JavaBeans platform?

• Answer: JSP applications run on a servlet container like Apache Tomcat. JavaBeans are
reusable components used in JSP to encapsulate data and logic, promoting separation of
concerns. They can store user data, perform business logic, and interact with databases.

7. Explain the support of MVC paradigm.

• Answer: MVC (Model-View-Controller) pattern:

o Model: JavaBeans or POJOs holding business data.

o View: JSP – renders UI using model data.

o Controller: Servlet – processes user input and interacts with model/view. JSP fits
perfectly in the View layer of the MVC architecture.

8. How many technologies are co-related with JSP?

• Answer:

o Servlets

o JavaBeans

o JSTL

o EL (Expression Language)

o AJAX

o JDBC

o Tag Libraries
o Frameworks like Struts, Spring MVC

9. What are the services provided by the web? Explain:

• WSDL (Web Services Description Language):

o XML-based language to describe web services and how to access them.

• SOAP (Simple Object Access Protocol):

o Protocol for exchanging structured information in web services using XML over HTTP.

10. Which one is better – either Servlet or JSP? Explain in brief.

• Answer:

o Servlets are better for processing logic and backend tasks.

o JSP is better for designing the presentation layer (UI).

o Best practice: Use Servlets as Controllers and JSP as Views (in MVC).

Would you like me to compile this into a formatted PDF or document file as your assignment
submission?

Lab Assignment 7
Here is the detailed answer for Lab Assignment 7 (PHP-related):

1. What is PHP? How PHPMyAdmin works?

• PHP (Hypertext Preprocessor) is a widely-used open-source server-side scripting language


designed for web development. It can be embedded into HTML to add dynamic functionality
to websites.
• PHPMyAdmin is a free tool written in PHP intended to handle the administration of MySQL
over the web. It allows users to:
o Create, modify, and delete databases
o Execute SQL queries
o Manage users and permissions
o Import/export data in various formats

2. Explain superglobals concept related to PHP


Superglobals are built-in variables in PHP that are always accessible, regardless of scope. Common
superglobals include:

• $_GET: Retrieves data sent via URL parameters


• $_POST: Retrieves data sent via POST method (e.g., form submission)
• $_REQUEST: Contains both GET and POST data
• $_SESSION: Stores session variables
• $_COOKIE: Stores cookie values
• $_FILES: Handles file uploads
• $_SERVER: Server environment information
• $_ENV: Environment variables
• $_GLOBALS: Access global variables

3. How we can perform operations like file handling with help of PHP?

PHP supports file operations such as:

• Open a file: fopen()


• Read from a file: fread(), fgets()
• Write to a file: fwrite()
• Close a file: fclose()
• Example:
• $file = fopen("data.txt", "w");
• fwrite($file, "Hello, File!");
• fclose($file);

4. What is the use of cookies and sessions in PHP?

• Cookies: Store data on the client-side in the user's browser.


o Example: Remembering user login.
o Syntax: setcookie("user", "Sanskruti", time()+3600);
• Sessions: Store data on the server-side for each user.
o Example: Shopping cart data.
o Syntax:
o session_start();
o $_SESSION["user"] = "Sanskruti";

5. Explain MySQLi and PHP PDO

• MySQLi (MySQL Improved):


o Only works with MySQL database
o Supports procedural and object-oriented approaches
• PDO (PHP Data Objects):
o Supports multiple database types (MySQL, PostgreSQL, SQLite, etc.)
o Object-oriented only
o Provides a consistent interface regardless of the database
6. What are the functions used in PHP?

Common built-in PHP functions include:

• String: strlen(), str_replace(), strpos()


• Array: array_push(), count(), array_merge()
• Date: date(), time()
• Math: abs(), pow(), round()
• Custom functions:
• function greet($name) {
• return "Hello, $name!";
• }

7. What is the concept of pattern matching in PHP?

• Pattern matching is done using regular expressions.


• PHP provides two functions:
o preg_match(): Checks if a pattern exists in a string
o preg_replace(): Replaces matches with another string
o Example:
o if (preg_match("/[0-9]{10}/", $phone)) {
o echo "Valid phone number";
o }

8. Explain the following content

• WAP (Wireless Application Protocol):


o A protocol for accessing information over a mobile wireless network.
o Used in early mobile internet devices before modern smartphones.
• WML (Wireless Markup Language):
o A markup language used to design WAP pages.
o Similar to HTML but optimized for mobile devices.

9. List out with examples regarding control statements used in PHP

• If-else:
• if ($a > $b) {
• echo "A is greater";
• } else {
• echo "B is greater";
• }
• Switch-case:
• switch ($color) {
• case "red": echo "Color is red"; break;
• default: echo "Other color";
• }
• Loops:
o for, while, do...while, foreach
o Example:
o for ($i = 0; $i < 5; $i++) {
o echo $i;
o }

10. What are the operators we can perform with help of PHP?

• Arithmetic: +, -, *, /, %
• Assignment: =, +=, -=
• Comparison: ==, !=, >, <, ===, !==
• Logical: &&, ||, !
• String: . (concatenation)
o Example:
o $full = $first . " " . $last;

11. Syntax of PHP & how we can comment part in PHP

• PHP code is written within:


• <?php
• // your PHP code
• ?>
• Comments in PHP:
o Single-line: // or #
o Multi-line: /* ... */
o Example:
o // This is a single-line comment
o /* This is a
o multi-line comment */

Let me know if you want a PDF version or presentation for this!

Lab Assignment 8
Here's the detailed explanation for Lab Assignment 8 based on Apache Struts (a popular MVC framework for
Java web applications):

1. What is meant by Struts? Which version is currently used?

• Struts is an open-source web application framework for developing Java EE web applications using the
MVC (Model-View-Controller) architecture.

• It helps developers separate the model (data), view (UI), and controller (logic).

• Latest stable version (as of 2025): Struts 2.5.x / 6.x (Struts 2 is the widely adopted version; Struts 1 is
deprecated).

2. Explain features and working of Struts 2


Features:

• MVC architecture

• Easy integration with other frameworks

• Annotation-based configuration

• AJAX support

• Powerful tag libraries

• Interceptors for common tasks (logging, validation, etc.)

Working:

1. User sends a request.

2. Struts front controller (FilterDispatcher) processes the request.

3. The request is passed through interceptors.

4. The Action class executes business logic.

5. Result is returned to a specific view (JSP/HTML).

3. Which type of tags are implemented in Struts 2?

Struts 2 provides custom tag libraries that help in creating UI elements easily. Tag types:

• UI Tags: <s:form>, <s:textfield>, <s:submit>, etc.

• Control Tags: <s:if>, <s:else>, <s:iterator>, etc.

• Data Tags: <s:property>, <s:set>, etc.

• Ajax Tags: Used for creating dynamic UIs with AJAX.

4. How Action class works in Struts 2?

• Action classes are responsible for handling user requests and business logic.

• They implement the Action interface or extend ActionSupport class.

• Method (like execute()) is triggered by a user request.

• Returns a String result name like "success" or "error", which maps to a specific view (JSP).

5. Explain the architecture of Struts

Struts architecture follows MVC:

• Model: Business logic and data (Java classes, databases).

• View: JSP, HTML files for UI.

• Controller: FilterDispatcher or StrutsPrepareAndExecuteFilter (in Struts 2) handles all requests.


Workflow:

1. User requests a URL.

2. Controller maps the URL to an Action.

3. Interceptors are executed.

4. Action executes business logic.

5. Controller selects appropriate view for response.

6. Why interceptors are applied in Struts?

Interceptors are objects that allow pre-processing and post-processing of a request. Uses:

• Input validation

• Logging

• File upload handling

• Authentication/Authorization

• Modifying request/response data

Struts 2 uses an interceptor stack, and we can create custom interceptors too.

7. How can we validate a website developed in Struts?

Validation in Struts can be done by:

1. XML-based validation: Create a file named ActionClassName-validation.xml.

2. Annotation-based validation: Use annotations like:

3. @RequiredStringValidator(message = "Field is required")

4. The framework automatically validates form fields before calling the action method.

5. If validation fails, errors are shown on the form.

8. What is meant by localization in Struts?

Localization refers to adapting your application to different languages and regions.

• Done using resource bundles (.properties files like ApplicationResources_en.properties).

• Use Struts tags like <s:text name="welcome.message"/> to fetch localized text.

• Based on the user's locale, Struts loads the correct language file.

9. How exception handling works in Struts?

Struts allows custom exception handling using:

1. Global exception mappings in struts.xml:


2. <exception-mapping exception="java.lang.Exception" result="error"/>

3. Try-catch blocks in Action classes.

4. Use of @ExceptionMapping annotation (if using annotations).

5. Redirects the user to a specific error page if an exception occurs.

10. Explain the concept of annotation in Struts

Struts 2 supports annotation-based configuration which reduces the need for XML.

Common annotations:

• @Action: Maps a method to a URL.

• @Result: Maps return string to a view.

• @Namespace: Defines URL namespace.

• @InterceptorRef: Applies an interceptor.

• @Validations: For form field validation.

Example:

@Action(value="/login", results={

@Result(name="success", location="/welcome.jsp"),

@Result(name="error", location="/login.jsp")

})

public String execute() {

// logic

Let me know if you'd like all this converted into a PDF, Word doc, or PowerPoint!

Lab Assignment 9
Here is the detailed explanation for Lab Assignment 9 based on AngularJS and Angular:

1. What is AngularJS? Explain its features.

AngularJS is a JavaScript-based open-source front-end web framework developed by Google to build dynamic
single-page applications (SPAs).

Features:

• MVC architecture
• Two-way data binding

• Dependency injection

• Directives (custom HTML tags/attributes)

• Templates and expressions

• Built-in services like $http, $location

• Filters and form validation

• Routing support

2. MVC of AngularJS – Explain.

MVC (Model-View-Controller) is a design pattern:

• Model: Manages the application data (JavaScript objects).

• View: Handles the UI (HTML).

• Controller: Business logic that connects Model and View.

AngularJS binds these components using two-way data binding, allowing real-time synchronization between
the model and view.

3. What are the modules introduced in AngularJS?

Modules in AngularJS define an application:

var app = angular.module("myApp", []);

Some core modules:

• ngRoute – for routing

• ngAnimate – animations

• ngResource – interaction with RESTful services

• ngCookies – handling cookies

• ngMessages – displaying messages/alerts

4. Explain JS filters with examples.

Filters format data in the view. Common filters:

• uppercase / lowercase

• currency

• date

• filter (search)

• limitTo
Example:

{{ 1234.56 | currency }} // ₹1,234.56

5. On which platform can you implement JS code?

JavaScript (and AngularJS) can be implemented on:

• Web browsers (Chrome, Firefox, Edge)

• Mobile platforms (via hybrid apps like Ionic)

• Server-side (with Node.js)

6. How component.js file works in Angular?

In Angular (2+):

• A component.js file defines a UI block.

• It uses the @Component decorator with metadata like template, selector, etc.

Example:

@Component({

selector: 'app-header',

templateUrl: './header.component.html'

})

export class HeaderComponent {}

7. How can we create a project in Angular?

Steps:

1. Install Angular CLI:

2. npm install -g @angular/cli

3. Create a project:

4. ng new my-app

5. Navigate into project:

6. cd my-app

7. Run the app:

8. ng serve

8. Which software is used to run AngularJS?

• Browser (for running the app)


• Text Editor (like VS Code)

• Node.js & npm (for package management)

• Live Server/Angular CLI (for Angular 2+)

• Web server (Apache, Nginx – for deployment)

9. How the database can we fetch with help of AngularJS?

AngularJS uses the $http service or Angular’s HttpClient (in Angular 2+) to communicate with backends via API
calls.

Example using $http:

$http.get("api/data").then(function(response){

$scope.data = response.data;

});

10. What is meant by bootstrap-wrapper?

A Bootstrap wrapper is a container/component that wraps Bootstrap UI elements inside a framework like
Angular or jQuery.

In Angular, Bootstrap can be wrapped using:

• ng-bootstrap

• ngx-bootstrap

It helps in integrating Bootstrap styling with Angular components seamlessly.

11. ComponentFixture – what does it mean?

ComponentFixture is used in Angular testing.

• It's a test harness for interacting with the component and its DOM.

• Created using TestBed.createComponent().

Example:

let fixture: ComponentFixture<AppComponent>;

fixture = TestBed.createComponent(AppComponent);

12. @Component – What is it and why do we use it?

• @Component is a decorator in Angular used to define a component.

• It provides metadata about the component (selector, template, etc.)

• It's used to tell Angular how to process and display the component.
Example:

@Component({

selector: 'app-root',

templateUrl: './app.component.html'

})

Why use it?

• It marks a class as a component and lets Angular know how to render and use it in templates.

Let me know if you'd like this in a PDF/Word format or slides for submission!

Lab Assignment 10
Here is the detailed explanation of Lab Assignment 10 based on Enterprise JavaBeans (EJB):

1. What is meant by EJB?

EJB (Enterprise Java Bean) is a server-side software component that encapsulates business logic of an
application. It is a part of Java EE (Jakarta EE) specification and is used to build scalable, secure, and
transactional applications.

Key features:

• Managed by the EJB container.

• Supports transaction management.

• Enables security, concurrency, and remote access.

2. How can we create web applications with help of EJB platform?

To create web apps using EJB:

1. Create EJB module using an IDE like Eclipse or IntelliJ.

2. Write business logic in Session Beans or Message-Driven Beans.

3. Create a Web Module (WAR) to interact with EJBs.

4. Use JNDI to look up EJBs in the client layer.

5. Package as EAR (Enterprise Archive) or deploy separately to the server.

6. Deploy to an EJB container like JBoss, GlassFish, WildFly, etc.

3. Explain the types of Enterprise Java Beans, include benefits also

There are three types of EJBs:


Type Description Use Case Benefits

Represents a task or Stateless/Stateful


Session Bean Easy to manage business logic
process processes

Entity Bean Represents data stored in Previously used for DB but


Persistence
(deprecated) a DB replaced by JPA

Message-Driven Bean Handles asynchronous Enables loosely coupled


Integrates with JMS
(MDB) messages architecture

Benefits:

• Transaction and security management

• Scalability and load balancing

• Abstraction of complex enterprise logic

• Reusability and portability

4. Draw and explain the life cycle of EJB

Session Bean Lifecycle:

• Stateless:

o Does not retain client state.

o Lifecycle: new → setSessionContext() → ejbCreate() → business method → ejbRemove()

• Stateful:

o Retains state for a client.

o Lifecycle: new → setSessionContext() → ejbCreate() → multiple business calls →


ejbPassivate()/ejbActivate() → ejbRemove()

MDB Lifecycle:

• Message is received → onMessage() called → EJB container manages instance lifecycle.

5. What is .gradle extension used for?

Gradle is a build automation tool. .gradle files (like build.gradle) define:

• Project dependencies

• Build tasks

• Plugins

• Versioning and repositories

Example snippet:

dependencies {
implementation 'javax.ejb:javax.ejb-api:3.2'

6. Explain POM.xml file

POM (Project Object Model) is the core file in Maven used to manage:

• Project metadata

• Dependencies

• Plugins

• Build lifecycle

Sample snippet:

<dependencies>

<dependency>

<groupId>javax.ejb</groupId>

<artifactId>javax.ejb-api</artifactId>

<version>3.2</version>

</dependency>

</dependencies>

7. On which basis we decide dependencies of a project?

Dependencies are chosen based on:

• Functionality required (e.g., EJB, JPA, Servlet API)

• Frameworks used (Spring, Hibernate, etc.)

• Build tool (Gradle/Maven)

• Environment/Container support

• Version compatibility

• License and community support

8. What is the process to deploy a project?

Steps to deploy an EJB-based project:

1. Build the project (WAR/EAR/JAR).

2. Choose an EJB-supported server (e.g., JBoss, GlassFish).

3. Copy the build to server’s deploy directory.

4. Start/restart the server.


5. Access the application via the configured URL.

6. Monitor using the server’s admin console.

9. What are the packages used in EJB? List out.

Common EJB-related packages:

Package Description

javax.ejb Core EJB interfaces and annotations

javax.annotation Common Java EE annotations

javax.persistence Used with JPA for entity beans

javax.transaction Transaction management

javax.interceptor Interceptor mechanisms

javax.jms Java Messaging Service (for MDBs)

Let me know if you'd like diagrams or slides for the EJB lifecycle explanation too!

You might also like