You are on page 1of 9

🔥BCS-053 🔥

💙
Web Programming✔
✔@Bca studies

👍 👍
(2021-22)

🔥 🔥
100% guranteed
● Most Important question

1. Explain the following HTML elements :


(i) < TEXTAREA > tag
Sol. <textarea>: The Textarea element. The <textarea> HTML element represents a multi-line plain-text editing control,
useful when you want to allow users to enter a sizeable amount of free-form text, for example a comment on a review or
feedback form.
(ii) < TABLE > tag
Sol. The <table> tag defines an HTML table. An HTML table consists of one <table> element and one or more <tr>, <th>,
and <td> elements. The <tr> element defines a table row, the <th> element defines a table header, and the <td> element
defines a table cell.
(iii) ANCHOR element
Sol. Anchor tag- The HTML code for creating a link to another page or to a particular section within a page. It is also
commonly called an "h-ref." For example: -The <a> tag defines a hyperlink, which is used to link from one page to
another.
(iv) < MENU > tag
Sol. HTML <menu> tag specifies a list or menu of commands that a user can perform or activate. It is used for creating
context menu as well as lists menu.

2. How is WML different than HTML ? Write WML script that displays your enrolment number and name in the centre of the
screen?
3. Discuss the advantages of Web 2.0 over its previous version. Explain with the help of example?
Sol. Advantages of web 2.0
● Available at any time, any place.
● Variety of media.
● Ease of usage.
● Learners can actively be involved in knowledge building.
● Can create dynamic learning communities.
● Everybody is the author and the editor, every edit that has been made can be tracked.
● User-friendly.
● Updates in the wiki are immediate and it offers more sources for researchers.
● It provides real-time discussion.
4. What is session tracking ? Explain the use of cookies for session tracking with the help of an example?
Sol. Session Tracking tracks a user's requests and maintains their state. It is a mechanism used to store information on
specific users and in order to recognize these user's requests when they connect to the web server. HTTP is a stateless
protocol where each request to the server is treated like a new request.
Cookies are the mostly used technology for session tracking. Cookie is a key value pair of information, sent by the server
to the browser. This should be saved by the browser in its space in the client computer. Whenever the browser sends a
request to that server it sends the cookie along with it.
5. What are the uses of GET and POST methods of HTTP ? Also explain the differences between GET and POST?
Sol. The GET Method:-
GET is used to request data from a specified resource.

GET is one of the most common HTTP methods.

Note that the query string (name/value pairs) is sent in the URL of a GET request:

/test/demo_form.php?name1=value1&name2=value2
Some other notes on GET requests:

● GET requests can be cached


● GET requests remain in the browser history
● GET requests can be bookmarked
● GET requests should never be used when dealing with sensitive data
● GET requests have length restrictions
● GET requests are only used to request data (not modify)
The POST Method:-
POST is used to send data to a server to create/update a resource.

The data sent to the server with POST is stored in the request body of the HTTP request:

POST /test/demo_form.php HTTP/1.1


Host: w3schools.com

name1= value1&name2=value2
POST is one of the most common HTTP methods.

Some other notes on POST requests:

● POST requests are never cached


● POST requests do not remain in the browser history
● POST requests cannot be bookmarked
● POST requests have no restrictions on data length

6. Explain the JSP compilation time error and JSP request time errors?
Sol.
1. Translation Time Error : This type of Error occurs during the initial request. When a JSP page is first requested and
goes through the initial translation from a JSP source file into a corresponding Servlet class file. These errors are usually
the result of compilation failures and are known as Translation Time Errors. They are reported to the requesting Client with
an Error Status Code 500 or Server Error and usually contain the reported compilation error. Translation Time Errors are
handled by the JSP Engine.

2. JSP Request Time Error : This type of Error occurs during subsequent requests. These Errors are Run-Time errors
that can occur in either the body of the JSP page or in some other object that is called from the body of the JSP Page.
Request Time Errors result in an Exception being thrown. These Exceptions can be caught and appropriately handled in
the body of the calling JSP, which would be the end of the error. Those Exceptions that are not caught result in the
forwarding of the Client request, including the Uncaught Exception, to the Error Page specified by the offending JSP.
7. What is the purpose of class selector in CSS ? Explain with the help of an example.
Sol. The .class selector is used to select all elements which belong to a particular class attribute. In order to select the
elements with a particular class, use the period (.) character specifying the class name ie., it will match the HTML element
based on the contents of their class attribute. The class name is mostly used to set the CSS property to a given class.

Syntax:

.class {
// CSS property
}
Example 1: This example demonstrates the class Selector for the specific HTML element.

<!DOCTYPE html>

<html>

<head>

<style>
.geeks {

color: green;

.gfg {

background-color: yellow;

font-style: italic;

color: green;

</style>

</head>

<body style="text-align:center">

<h1 class="geeks">

GeeksforGeeks

</h1>

<h2>.class Selector</h2>

<div class="gfg">
<p>GeeksforGeeks: A computer science portal</p>

</div>

</body>

</html>

8. A student fee table contains information about student enrolment number and amount of fee paid by a student. A student
can pay fee only once. Assuming that a connection has already been created, write JSP code that accesses data from the
database for the enrolment number "1701" and displays this data. Make suitable assumptions, if any?
9. Explain the uses of XML CSS and XML, XSLT?
Sol. CSS:- CSS can be used to display the contents of the XML document in a clear and precise manner. It gives the
design and style to whole XML document. Define the style rules for the text elements such as font-size, color, font-weight,
etc.
XML XSLT :- With XSLT you can add/remove elements and attributes to or from the output file. You can also rearrange
and sort elements, perform tests and make decisions about which elements to hide and display, and a lot more. XSLT
uses XPath to find information in an XML document.
10. Define the following terms :
(i) WML Tasks
Sol. A WML task is an element that specifies an action to be performed by the browser, rather than something to be
displayed. For example, the action of changing to a new card is represented by a <go> task element, and the action of
returning to the previous card visited is represented by a <prev> task element. Task elements encapsulate all the
information required to perform the action.
WML provides following four elements to handle four WML tasks called go task, pre task, refresh task and noop taks.
(ii)XML Schemas
Sol. XML schema is a language which is used for expressing constraint about XML documents. There are so many
schema languages which are used now a days for example Relax- NG and XSD (XML schema definition).

An XML schema is used to define the structure of an XML document. It is like DTD but provides more control on XML
structure.
(iii)WAP Protocol Stack
Sol. WAP stands for Wireless Application Protocol. It is a protocol designed for micro-browsers and it enables the access
of internet in the mobile devices. It uses the mark-up language WML (Wireless Markup Language and not HTML), WML is
defined as XML 1.0 application.
WAP Model:
The user opens the mini-browser in a mobile device. He selects a website that he wants to view. The mobile device sends
the URL encoded request via network to a WAP gateway using WAP protocol.

(iv) HTML DOM


Sol. The Document Object Model (DOM) is a programming interface for HTML and XML(Extensible markup language)
documents. It defines the logical structure of documents and the way a document is accessed and manipulated
Properties of DOM: Let’s see the properties of the document object that can be accessed and modified by the document
object.

● Window Object: Window Object is always at top of the hierarchy.


● Document object: When an HTML document is loaded into a window, it becomes a document object.
● Form Object: It is represented by form tags.
● Link Object: It is represented by link tags.
● Anchor Object: It is represented by a href tags.
● Form Control Elements:: Form can have many control elements such as text fields, buttons, radio buttons, and
checkboxes, etc.
Methods of Document Object:

● write(“string”): Writes the given string on the document.


● getElementById(): returns the element having the given id value.
● getElementsByName(): returns all the elements having the given name value.
● getElementsByTagName(): returns all the elements having the given tag name.
● getElementsByClassName(): returns all the elements having the given class name.
11. Explain the method getElementBy Id( ) in JavaScript with the help of an example?
Sol. The getElementById() is a DOM method used to return the element that has the ID attribute with the specified value.
This is one of the most common methods in the HTML DOM and is used almost every time we want to manipulate an
element on our document. This method returns null if no elements with the specified ID exists. The ID should be unique
within a page. However, if more than one element with the specified ID exists, it returns the last element in the javascript
code.

Example-1
In the following example, there exists a paragraph tag with the inner text "GetElementById" and with an id called
"element". Using the DOM method "document.getElementById()" the text inside the paragraph tag is accessed
and the value is displayed in the output. Without ".innerHtml" the document.getElementById can't read the inner
text part of any tag.

<html>
<body>
<p id="element">GetElementById</p>
<script>
var s = document.getElementById("element").innerHTML;
document.write(s);
</script>
</body>
</html>

Output
GetElementById
GetElementById
12. Explain the following with the help of an example/diagram, if needed :
(a) Web container
(b) Request and Response in the context of HTTP
(c) Scriptlets
(d) DriverManager Class
(e) Controller in the context of MVC 8architecture (±) < jsp : param > tag
(f) Events in HTML
(g) < jsp : useBean >
(h) < sql : query >
(i) Social Networking
(j) XML Schemas
(k) <details> and <summary> tags cif HTML5
(l) Session Object
(m) Need of JSP
(n) GET Method of HTTP
(o) include Directive in JSP
(p) JDBC-ODBC Bridge
(q) Scriplets in JSP
(r) Uses of <div> tag
(s) Page Directive of JSP
(t) POST Method of HTTP
(u) DriverManager class in JSP
(v) Loading a JDBC database driver
(w) Processing the result obtained from
database access, while using JSP
(x) Session Management
(y) Include Directive
(z) Exception handling using JSP
13. List the techniques for session tracking. Explain any one of them?
Sol. Methods of Session Tracking
There are four techniques used in Session Tracking:
1) Cookies
2) Hidden Form Field
3) URL Rewriting
4) HttpSession
1) Cookies
Cookies are small piece of information sent by web server in response header and gets stored in browser side. A web
server can assign a unique session ID to each web client. The cookies are used maintain the session. The client can
disable the cookies.
2) Hidden Form Field
The hidden form field is used to insert the information in the webpages and this information is sent to the server. These
fields are not viewable to the user directly.

For example:
<input type = hidden' name = 'session' value = '12345' >
3) URL Rewriting
Append some extra data through URL as request parameters with every request and response. URL rewriting is a better
way to maintain session’s management and work for the browsers.

For example:
http://tutorialride.com/servlet.htm;sessionid=54321
4) HttpSession Object
The HttpSession object represents a user session. The HttpSession interface creates a session between an HTTP client
and HTTP server. A user session contains information about the user across multiple HTTP requests.

For example:
HttpSession session = request.getSession( );
Session.setAttribute("username", "password");
14. Explain the life cycle of JSP with the help of a diagram?
Sol. Life cycle of JSP
A Java Server Page life cycle is defined as the process that started with its creation which later translated to a servlet and
afterward servlet lifecycle comes into play. This is how the process goes on until its destruction.

Following steps are involved in the JSP life cycle:

● Translation of JSP page to Servlet


● Compilation of JSP page(Compilation of JSP into test.java)
● Classloading (test.java to test.class)
● Instantiation(Object of the generated Servlet is created)
● Initialization(jspInit() method is invoked by the container)
● Request processing(_jspService()is invoked by the container)
● JSP Cleanup (jspDestroy() method is invoked by the container)
15. Compare and contrast :
(i) Static web pages and Dynamic web pages 2

Sol.
(ii) 2-Tier architecture and 3-Tier architecture
Sol.
(iii) Static web page vs Dynamic web page

Sol.
16. Explain the image and navigational
elements of WML with the help of an exam?
Sol. WML provides you an option to link various cards using links and then navigate through different cards.

There are two WML elements, <anchor> and <a>, which can be used to create WML links.

WML <anchor> Element:


The <anchor>...</anchor> tag pair is used to create an anchor link. It is used together with other WML elements called
<go/>, <refresh> or <prev/>. These elements are called task elements and tell WAP browsers what to do when a user
selects the anchor link

You can enclose Text or image along with a task tag inside <anchor>...</anchor> tag pair.

The <anchor> element supports the following attributes:


The <img> element is used to include an image in a WAP card. WAP-enabled wireless devices only supported the
Wireless Bitmap (WBMP) image format.

WBMP images can only contain two colors: black and white. The file extension of WBMP is ".wbmp" and the MIME type of
WBMP is "image/vnd.wap.wbmp".
17. Explain the uses of the following WAP elements :
(i) <pre>
(ii)<em>
(iii)<img src>
(iv) <set var>
18. Explain the use of AJAX?
Sol. AJAX = Asynchronous JavaScript and XML. AJAX is a technique for creating fast and dynamic web pages. AJAX
allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes.
This means that it is possible to update parts of a web page, without reloading the whole page.
19. What is a cookie ? Why is it needed ? Write the command to create a new cookie having a name testcookie. Also
write the command to set the life of this cookie to 30 minutes?
Sol. cookie is a piece of data from a website that is stored within a web browser that the website can retrieve at a later
time. Cookies are used to tell the server that users have returned to a particular website.
Click 'Content' in the Top Menu.
Click 'Site Footer' in the left-hand menu.
Click into the 'Custom Footer Content' box and then click on the small 'HTML' icon in the toolbar.
Select your Cookie Consent fragment from the drop-down list that appears and click 'Update'.
Click 'Save Changes'
You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry
date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.

Example
You can try to run the following example to set cookies to expire in 30 minutes

Live Demo

<html>
<head>
<script>
<!--
function WriteCookie() {
var now = new Date();
var minutes = 30;
now.setTime(now.getTime() + (minutes * 60 * 1000));
cookievalue = escape(document.myform.customer.value) + ";"

document.cookie="name=" + cookievalue;
document.cookie = "expires=" + now.toUTCString() + ";"
document.write ("Setting Cookies : " + "name=" + cookievalue );
}
//-->
</script>
</head>
<body>
<form name="myform" action="">
Enter name: <input type="text" name="customer"/>
<input type="button" value="Set Cookie" onclick="WriteCookie()"/>
</form>
</body>
</html>
20. What is the need of HTML DOM ?
Sol. The Document Object Model (DOM) is a programming interface for web documents. It represents the page so that
programs can change the document structure, style, and content. The DOM represents the document as nodes and
objects; that way, programming languages can interact with the page.
21. Consider the following HTML document :
<html>
<head> Test </head>
<body>
<p id = "Welcome"> Welcome to
Examination </p>
</body>
</html>
22. Write JavaScript code in this HTML
document that replaces the "Welcome to Examination" to "Welcome to JavaScript" when this HTML document is
displayed in web browser. Make suitable assumptions, if any?

You might also like