December 2022 [Free] Solved BCS-053 Web Programming

Hey there! Welcome to KnowledgeKnot! Don't forget to share this with your friends and revisit often. Your support motivates us to create more content in the future. Thanks for being awesome!

1. (a) Write a JavaScript and related HTML code which changes the content of a paragraph having an id “IGNOU” from “BCA Examination” to the text “The out of distance education”. [Marks: 4]

Answer:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Change Content</title>
</head>
<body>
    <p id="IGNOU">BCA Examination</p>
    <button onclick="changeContent()">Change Content</button>

    <script>
        function changeContent() {
            document.getElementById("IGNOU").innerHTML = "The out of distance education";
        }
    </script>
</body>
</html>
        

1. (b) Explain the box model of HTML with the help of a diagram. [Marks: 3]

Answer:

The box model in HTML consists of four parts:

  • Content: The actual content of the box, such as text or images.
  • Padding: Clears an area around the content, inside the border.
  • Border: A border surrounding the padding (if any) and content.
  • Margin: Clears an area outside the border, creating space between the box and other elements.

Diagram:


+----------------------+
|     Margin           |
|  +---------------+   |
|  |   Border      |   |
|  |  +---------+  |   |
|  |  | Padding  |  |   |
|  |  |  +-----+ |  |   |
|  |  |  |Content| |  |   |
|  |  +---------+  |   |
|  +---------------+   |
+----------------------+
        

1. (c) Create an XML document having two records with the structure : [Marks: 3]

  • Name which have first name and last name of a student.
  • Programme which is name of the programme of the student.

Answer:


<?xml version="1.0" encoding="UTF-8"?>
<students>
    <student>
        <name>
            <firstName>John</firstName>
            <lastName>Doe</lastName>
        </name>
        <programme>Computer Science</programme>
    </student>
    <student>
        <name>
            <firstName>Jane</firstName>
            <lastName>Smith</lastName>
        </name>
        <programme>Software Engineering</programme>
    </student>
</students>
        

1. (d) What is a cookie? Why are the cookies used? Write the code that can create a new cookie. [Marks: 4]

Answer:

A cookie is a small piece of data that is stored by the web browser and sent to the server with every HTTP request. Cookies are used to store information such as user preferences, authentication tokens, and session information.

Code to create a new cookie:


document.cookie = "username=JohnDoe; expires=Fri, 31 Dec 2024 23:59:59 GMT; path=/";
        

1. (e) Write a JSP script that prints numbers 1 to 5 on a separate HTML paragraph. [Marks: 4]

Answer:


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"%>
<html>
<head>
    <title>Numbers</title>
</head>
<body>
    <% 
        for (int i = 1; i <= 5; i++) {
            out.println("<p>" + i + "</p>");
        }
    %>
</body>
</html>
        

1. (f) List the advantages of JSP over Servlet. [Marks: 2]

Answer:

  • Simpler Syntax: JSP has a more simplified and readable syntax compared to Servlets, which require more code to generate dynamic content.
  • Separation of Concerns: JSP allows the separation of business logic (Java code) from the user interface (HTML), making the development process easier.
  • Built-in Tag Libraries: JSP provides tag libraries (JSTL) to reduce the amount of Java code needed in the page.

2. (a) Explain the features of Web 2.0. Explain any three technologies of Web 2.0. [Marks: 5]

Answer:

Web 2.0 is the second generation of the World Wide Web, focused on user-generated content, usability, and collaboration. Key features include:

  • User-Centric: Emphasizes user participation and interaction, with websites allowing users to create and share content easily.
  • Social Networking: Websites enable users to create profiles, interact with others, and share content, fostering communities.
  • Rich User Interfaces: Web 2.0 provides interactive and dynamic web applications with enhanced user interfaces using AJAX, making web applications more responsive.

Three technologies of Web 2.0:

  1. AJAX (Asynchronous JavaScript and XML): AJAX allows for the creation of dynamic and interactive web pages by loading data in the background without refreshing the page.
  2. RSS (Really Simple Syndication): RSS allows users to subscribe to content from websites and receive updates automatically in a feed reader.
  3. Social Media Platforms: Platforms like Facebook, Twitter, and Instagram are powered by Web 2.0 technologies, providing social networking and content sharing features.

2. (b) What is CSS ? Explain how CSS can be used for the following : [Marks: 5]
(i) Change the background colour of a page to red.
(ii) Change the font size of a paragraph to 17 points.
(iii) Changes colour of a paragraph

Answer:

CSS (Cascading Style Sheets) is a styling language used to describe the presentation of a document written in HTML or XML. It controls the layout, colors, fonts, and overall look of a webpage.

CSS can be used to:

  1. (i) Change the background color of a page to red:
  2. 
    body {
        background-color: red;
    }
                
  3. (ii) Change the font size of a paragraph to 17 points:
  4. 
    p {
        font-size: 17pt;
    }
                
  5. (iii) Change the color of a paragraph:
  6. 
    p {
        color: blue;
    }
                

3. (a) What is a DTD in the context of an XML document ? Given the following DTD : [Marks: 5]
<!ELEMENT University (Name, Address)>
<!ELEMENT Name (# PCDATA)>
<!ELEMENT Address (Location, Pincode)>
<!ELEMENT Location (# PCDATA)>
<!ELEMENT Pincode (# PCDATA)>
Create a document having two records, which are valid as per the DTD given above.

Answer:

A DTD (Document Type Definition) defines the structure and rules for an XML document. It specifies the allowed elements and their relationships in the XML document.

Here is an XML document that conforms to the provided DTD:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE University [
    <!ELEMENT University (Name, Address)>
    <!ELEMENT Name (#PCDATA)>
    <!ELEMENT Address (Location, Pincode)>
    <!ELEMENT Location (#PCDATA)>
    <!ELEMENT Pincode (#PCDATA)>
]>
<University>
    <Name>ABC University</Name>
    <Address>
        <Location>New York</Location>
        <Pincode>10001</Pincode>
    </Address>
</University>
<University>
    <Name>XYZ University</Name>
    <Address>
        <Location>Los Angeles</Location>
        <Pincode>90001</Pincode>
    </Address>
</University>
        

3. (b) Write the code in WML that creates the following table : [Marks: 5]

Course NameTeacher
Web ProgrammingABC
DBMSXYZ

Answer:


<?xml version="1.0" encoding="UTF-8"?>
<wml>
    <card id="tableCard" title="Course Table">
        <p>
            <table>
                <tr>
                    <td><b>Course Name</b></td>
                    <td><b>Teacher</b></td>
                </tr>
                <tr>
                    <td>Web Programming</td>
                    <td>ABC</td>
                </tr>
                <tr>
                    <td>DBMS</td>
                    <td>XYZ</td>
                </tr>
            </table>
        </p>
    </card>
</wml>
        

4. (a) Differentiate between the following : [Marks: 6]
(i) GET and POST methods
(ii) HTTP server and Web container
(iii) Action elements and JSP implicit

Answer:

(i) GET and POST methods:

  • GET: The GET method is used to request data from a specified resource. It appends data to the URL, which makes it visible to the user. It's suitable for fetching data without side effects.
  • POST: The POST method is used to send data to the server to create or update a resource. Data is sent in the request body, which makes it more secure compared to GET. It's used when submitting forms with sensitive data.

(ii) HTTP server and Web container:

  • HTTP server: It serves HTTP requests by handling the communication between the client (browser) and server. An HTTP server handles static content like HTML, CSS, and images.
  • Web container: A web container (or servlet container) manages Java Servlets and JSP pages. It processes dynamic content, such as handling servlets and Java-based web applications, and it also provides a runtime environment for these technologies.

(iii) Action elements and JSP implicit:

  • Action elements: These are tags in JSP used to interact with the server-side code and perform actions such as including files, forwarding requests, and sending responses (e.g., <jsp:include>, <jsp:forward>).
  • JSP implicit objects: These are objects automatically available to JSP pages without being explicitly declared. Examples include `request`, `response`, `session`, and `out`.

4. (b) What is an exception ? What are the different types of errors in JSP ? Give one example of each. [Marks: 4]

Answer:

An exception is an event that disrupts the normal flow of a program's execution. In Java, it is represented as an object that encapsulates the error details, including the type of error and where it occurred.

Types of errors in JSP:

  • Syntax errors: These errors occur when the JSP page contains invalid syntax. Example: Missing a closing tag in a JSP scriptlet.
  • 
    <%
        String name = "John"
    %>
    

    In the example above, the missing semicolon (`;`) will cause a syntax error.

  • Runtime errors: These errors occur during the execution of the JSP page. Example: Trying to access a null object.
  • 
    <%
        String text = null;
        out.println(text.length());
    %>
    

    This code will throw a `NullPointerException` at runtime.

  • Logical errors: These errors occur when the code runs successfully, but the logic is incorrect. Example: Incorrect calculations or business logic mistakes.
  • Example: Using the wrong formula for calculating interest.

5. Explain the following with the help of an example : [Marks: 2]
(a) DriverManager class
(b) PrepareStatement( ) method
(c) ResultSet object
(d) MVC architecture

Answer:

(a) DriverManager class:

The `DriverManager` class is used to manage database drivers and establish a connection to a database. It’s part of the Java JDBC API.


import java.sql.Connection;
import java.sql.DriverManager;

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb", "username", "password");
    

(b) PrepareStatement() method:

The `prepareStatement()` method in Java is used to create a SQL statement that can be executed multiple times with different parameters. It helps prevent SQL injection attacks and optimizes performance.


String sql = "INSERT INTO users (name, age) VALUES (?, ?)";
PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setString(1, "John");
stmt.setInt(2, 30);
stmt.executeUpdate();
    

(c) ResultSet object:

The `ResultSet` object in Java holds the data retrieved from a database query. It allows you to read and manipulate the result set returned by a query.


String sql = "SELECT * FROM users";
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
    String name = rs.getString("name");
    int age = rs.getInt("age");
    System.out.println(name + " is " + age + " years old.");
}
    

(d) MVC architecture:

The Model-View-Controller (MVC) architecture is a design pattern used for building web applications. It separates an application into three interconnected components:

  • Model: Represents the data and business logic of the application. It interacts with the database and updates the view as necessary.
  • View: Represents the UI elements and displays data from the model to the user.
  • Controller: Acts as an intermediary between the model and the view. It processes user input, updates the model, and refreshes the view.

public class UserController {
    private UserService userService;
    
    public UserController(UserService userService) {
        this.userService = userService;
    }

    public void showUserDetails(int userId) {
        User user = userService.getUser(userId);
        System.out.println("User Name: " + user.getName());
    }
}
    

Suggetested Articles