June 2023 [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) Consider the following information (6 marks)

Student NameProgramme code
First NameLast Name
RaviKumarBCA
AnanthMalikMCA

(i) Create an XML document for the data given in the table above. Use appropriate tags.

(ii) Create the DTD to validate the XML document created in part (i).

Answer:

(i) XML Document:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Students SYSTEM "students.dtd">
<Students>
    <Student>
        <FirstName>Ravi</FirstName>
        <LastName>Kumar</LastName>
        <ProgrammeCode>BCA</ProgrammeCode>
    </Student>
    <Student>
        <FirstName>Ananth</FirstName>
        <LastName>Malik</LastName>
        <ProgrammeCode>MCA</ProgrammeCode>
    </Student>
</Students>
    

(ii) DTD Document:


<!ELEMENT Students (Student+)>
<!ELEMENT Student (FirstName, LastName, ProgrammeCode)>
<!ELEMENT FirstName (#PCDATA)>
<!ELEMENT LastName (#PCDATA)>
<!ELEMENT ProgrammeCode (#PCDATA)>
    

1. (b) A database table consists of the following fields:

Programme (ProgrammeCode, Title, Duration)
Assuming that connection has been established with the database and a statement object “stmt” has been instantiated, write the code fragment to get a ResultSet object containing the list of all those programmes, whose duration is more than 1 year. (6 marks)

Answer:


try {
    // Define the SQL query to retrieve programmes with duration > 1 year
    String sql = "SELECT ProgrammeCode, Title, Duration FROM Programme WHERE Duration > 1";

    // Execute the query using the statement object
    ResultSet resultSet = stmt.executeQuery(sql);

    // Process the ResultSet
    while (resultSet.next()) {
        String programmeCode = resultSet.getString("ProgrammeCode");
        String title = resultSet.getString("Title");
        int duration = resultSet.getInt("Duration");

        // Print or process the results (example output)
        System.out.println("Programme Code: " + programmeCode + ", Title: " + title + ", Duration: " + duration);
    }

    // Close the ResultSet
    resultSet.close();
} catch (SQLException e) {
    // Handle SQL exception
    e.printStackTrace();
}
    

Explanation:

  • SQL Query: The `SELECT` query retrieves the `ProgrammeCode`, `Title`, and `Duration` fields from the `Programme` table where the `Duration` is greater than 1.
  • Execution: The `executeQuery` method is called on the statement object `stmt` to execute the query, and it returns a `ResultSet` object containing the result of the query.
  • Processing Results: The `while` loop iterates through the `ResultSet` to fetch and print the details of each programme meeting the criteria.
  • Exception Handling: The `try-catch` block ensures proper handling of any SQL exceptions that might occur during execution.

1. (c) Write a JavaScript script that changes the colour of a paragraph, whose id is "IGNOU", to green. (5 marks)

Answer:


<script>
    // Change the color of the paragraph with ID 'IGNOU' to green
    document.getElementById("IGNOU").style.color = "green";
</script>
    

Explanation:

  • Selection: The `getElementById` method is used to select the paragraph element by its `id`, which is `IGNOU` in this case.
  • Color Change: The `style.color` property is set to `green`, which changes the text color of the selected paragraph.

1. (d) Explain the GET method of HTTP with the help of an example. (3 marks)

Answer:

Explanation:

  • Definition: The HTTP GET method is used to request data from a server at a specified resource. It is primarily used to retrieve information, and it appends the parameters to the URL.
  • Characteristics:
    • Parameters are sent in the URL query string (visible to users).
    • Typically used for read-only operations.
    • Cached by browsers and can be bookmarked.

Example:


<!-- Example URL -->
GET /search?q=IGNOU HTTP/1.1
Host: www.example.com

// Server Response
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 200

<html>
    <body>
        <h1>Search Results for 'IGNOU'</h1>
    </body>
</html>
    

Explanation of Example:

  • The `GET` request in the example queries a search engine with the keyword `IGNOU` by appending `?q=IGNOU` to the base URL.
  • The server responds with an HTTP status `200 OK` along with the HTML content displaying the search results.
  • The GET method is visible in the browser's URL bar, making it unsuitable for transmitting sensitive data.

2. (a) Explain the MVC architecture with the help of a diagram. (5 marks)

Answer:

MVC (Model-View-Controller) is a design pattern used in software development to separate application logic into three interconnected components:

  • Model: Manages the data and business logic. It is responsible for retrieving, storing, and processing data.
  • View: Handles the user interface and presentation. It receives data from the model and displays it to the user.
  • Controller: Acts as an intermediary between the model and the view. It processes user inputs, updates the model, and instructs the view to update.

Diagram:


+---------------+          +-------------+          +---------------+
|               |          |             |          |               |
|   Controller  |<-------->|    Model    |<-------->|     View      |
|               |          |             |          |               |
+---------------+          +-------------+          +---------------+
    

Flow of Data:

  • The user interacts with the view.
  • The view sends the input to the controller.
  • The controller processes the input and updates the model.
  • The model notifies the view of changes, and the view updates the user interface accordingly.

2. (b) What are implicit objects in the context of JSP? Explain any two implicit objects of JSP. (5 marks)

Answer:

Implicit objects in JSP are predefined objects provided by the JSP container to simplify web application development. They are available by default in a JSP page and do not require explicit creation.

Examples:

  • request:
    • Type: HttpServletRequest
    • Purpose: Represents the HTTP request sent by the client.
    • Usage: Access request parameters, headers, and attributes.
    • Example:
      
      String username = request.getParameter("username");
                          
  • response:
    • Type: HttpServletResponse
    • Purpose: Represents the HTTP response sent back to the client.
    • Usage: Modify response headers, redirect users, or set cookies.
    • Example:
      
      response.sendRedirect("dashboard.jsp");
                          

3. (a) What is the need of session management in the context of HTTP? Define the terms–session and state in this context. Explain with the help of JSP script, how session object can be used to create a session. (7 marks)

Answer:

Need for Session Management: HTTP is a stateless protocol, meaning each request is independent and has no memory of previous interactions. Session management is needed to maintain user data across multiple requests, such as login information or user preferences.

  • Session: A session is a temporary, server-side storage mechanism to track user interactions across multiple requests.
  • State: The state represents the data associated with a user's session, such as authentication details or shopping cart contents.

Example JSP Script:

The session object in JSP allows developers to create and manage sessions. Here's an example:


<%@ page session="true" %>
<%
    // Create or retrieve the current session
    HttpSession session = request.getSession();

    // Store data in session
    session.setAttribute("username", "JohnDoe");

    // Retrieve data from session
    String username = (String) session.getAttribute("username");

    out.println("Hello, " + username + "!");
%>
    

Explanation:

  • The getSession() method retrieves the current session or creates a new one if none exists.
  • Session attributes are stored using setAttribute() and retrieved using getAttribute().
  • This script maintains the username across multiple HTTP requests.

3. (b) What is include directive in JSP? Explain its use with the help of an example. (3 marks)

Answer:

The include directive in JSP is used to include static or dynamic content from another file at the time of page translation. It promotes code reuse and reduces redundancy.

Syntax:


<%@ include file="filePath" %>
    

Example:

Consider a file footer.jsp with footer content:


<!-- footer.jsp -->
<hr>
<p>© 2024 MyWebsite. All rights reserved.</p>
    

In the main JSP file, include the footer as follows:


<%@ include file="footer.jsp" %>
<p>This is the main content of the page.</p>
    

Output: The content of footer.jsp will be included in the main page, resulting in:


<hr>
<p>© 2024 MyWebsite. All rights reserved.</p>
<p>This is the main content of the page.</p>
    

4. (a) Explain the following technologies in the context of Web 2.0: (i) Widgets (ii) Blogging (iii) Podcasting (6 marks)

Answer:

  1. Widgets: Widgets are small, interactive web components embedded within websites. They enhance functionality and user experience by providing quick access to features such as weather updates, clocks, or social media feeds, enabling dynamic interactions typical of Web 2.0 applications.
  2. Blogging: Blogging is a platform where individuals or groups create and publish content in an online journal format. Blogs are a cornerstone of Web 2.0 due to their interactive features like comments, shares, and RSS feeds that encourage user participation and collaboration.
  3. Podcasting: Podcasting allows creators to distribute digital audio or video files, enabling users to stream or download content. Web 2.0 facilitates podcast accessibility and engagement through syndication technologies like RSS feeds, encouraging subscription-based content delivery.

4. (b) Write HTML code to create a form as shown below: (4 marks)

Answer:

HTML Code:

The following code creates the requested form:


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Form</title>
 
</head>
<body>
    <form action="/submit" method="post">
        <label for="studentName">Student Name:</label>
        <input type="text" id="studentName" name="studentName">
        
        <label for="programmeCode">Programme Code:</label>
        <select id="programmeCode" name="programmeCode">
            <option value="BCA">BCA</option>
            <option value="MCA">MCA</option>
            <option value="CIT">CIT</option>
        </select>
        
        <button type="submit">SUBMIT</button>
    </form>
</body>
</html>
    

Explanation:

  • The form contains a text field for the student name and a dropdown for selecting the programme code.
  • The layout includes a border around the form and proper spacing between elements.
  • The submit button sends the data to the server using the POST method.

5. (a) What are the advantages of using CSS? What is an external style sheet? How is it linked to the related HTML document? (5 marks)

Answer:

Explanation:

  • Advantages of using CSS:
    • CSS separates content from design, making the HTML structure clean and easier to maintain.
    • It allows for consistency across multiple pages, as styles can be reused.
    • Improves page load speed since a single CSS file can be cached by the browser.
    • Enables responsive design to ensure compatibility with various devices and screen sizes.
    • Facilitates easier updates by modifying a single CSS file to apply changes globally.
  • External Style Sheet: An external style sheet is a separate file with a `.css` extension that contains all the CSS rules. It is used to apply styles to multiple HTML documents.
  • Linking an External Style Sheet: To link an external style sheet, the <link> tag is used in the <head> section of the HTML document. Example:
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Linking CSS</title>
        <link rel="stylesheet" href="styles.css">
    </head>
    <body>
        <h1>Hello, World!</h1>
    </body>
    </html>
                

5. (b) Explain the following WML elements with the help of an example: (i) WML Tables (ii) <anchor> element (5 marks)

Answer:

Explanation:

  1. WML Tables: WML supports tables for organizing content into rows and columns. An example:
    
    <card id="tableExample">
        <p>
            <table columns="2">
                <tr>
                    <td>Row 1, Col 1</td>
                    <td>Row 1, Col 2</td>
                </tr>
                <tr>
                    <td>Row 2, Col 1</td>
                    <td>Row 2, Col 2</td>
                </tr>
            </table>
        </p>
    </card>
                
  2. <anchor> Element: The <anchor> element in WML is used to create a hyperlink. It allows users to navigate to a different card or URL. Example:
    
    <card id="anchorExample">
        <p>
            <anchor title="Go to Next Card">
                Click Here
                <go href="#nextCard" />
            </anchor>
        </p>
    </card>
    <card id="nextCard">
        <p>You have navigated to the next card.</p>
    </card>
                

Suggetested Articles