Professional Documents
Culture Documents
Solutions
Solutions
Solutions
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<body>
<form>
<h1>RESERVATION FORM</h1>
<option>TATKAL</option>
<option>LADIES</option>
<option>GENRAL</option>
</select>
<option selected="selected">DELHI</option>
<option>MUMBAI</option>
<option>KOLKATA</option>
</form>
</body>
Features of CGI:
● It is a very well defined and supported standard.
● CGI scripts are generally written in either Perl, C, or maybe just a simple shell script.
● CGI is a technology that interfaces with HTML.
● CGI is the best method to create a counter because it is currently the quickest
● CGI standard is generally the most compatible with today’s browsers
Advantages of CGI:
● The advanced tasks are currently a lot easier to perform in CGI than in Java.
● It is always easier to use the code already written than to write your own.
● CGI specifies that the programs can be written in any language, and on any platform,
as long as they conform to the specification.
● CGI-based counters and CGI code to perform simple tasks are available in plenty.
Disadvantages of CGI:
There are some disadvantages of CGI which are given below:
● In Common Gateway Interface each page load incurs overhead by having to load the
programs into memory.
● Generally, data cannot be easily cached in memory between page loads.
● There is a huge existing code base, much of it in Perl.
● CGI uses up a lot of processing time.
●
8. What are the important uses of Cookies? Give five examples.
A 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.
cookie are intended to be used:
1. Session management. For example, cookies let websites recognize users
and recall their individual login information and preferences, such as sports
news versus politics.
2. Personalization. Customized advertising is the main way cookies are used to
personalize your sessions. You may view certain items or parts of a site, and
cookies use this data to help build targeted ads that you might enjoy.
3. Tracking. Shopping sites use cookies to track items users previously viewed,
allowing the sites to suggest other goods they might like and keep items in
shopping carts while they continue shopping.
Types of cookies
● Session cookies.
● Permanent cookies. ...
● First-party cookies. ...
● Third-party cookies. ...
● Flash cookies. ...
● Zombie cookies.
9. List the steps needed for processing the form using CGI.
This section expands on that to show how scripts are used to process web forms.
When the web server runs your CGI script, it passes information to the script within a
standard CGI environment. By providing the -c (or --CGI) option to REBOL, you are asking
REBOL to get the CGI environment information.
The CGI object contains a lot of information. Some of this may be useful to your script, but
what you want most is to get the results that were submitted in the web form (as shown
earlier).
When you see the results of the script above, you will notice that the web form data is
specially encoded to allow it to be passed back to the CGI script.
REBOL provides the DECODE-CGI function to make it easy to decode CGI form data.
10. What are the variables that an HTTP request provides to the server of a web page?
11. Write a JavaScript program that finds the greatest common divisor of two
numbers.
function gcd_two_numbers(x, y)
{
if ((typeof x !== 'number') || (typeof y !== 'number'))
return false;
x = Math.abs(x);
y = Math.abs(y);
while(y)
{
var t = y;
y = x % y;
x = t;
}
return x;
}
console.log(gcd_two_numbers(12, 13));
console.log(gcd_two_numbers(9, 3));
12. Write a JavaScript function that finds the maximum of three given numbers.
function max_of_three(x, y, z)
{
max_val = 0;
if (x > y) max_val = x;
else max_val = y;
if (z > max_val) max_val = z;
return max_val;
}
console.log(max_of_three(1,0,1));
console.log(max_of_three(0,-10,-20));
13. In the form to reserve the railway ticket add the following data validations using
JavaScript:
a. From City and To City are two different cities
b. Age of passenger should not be greater than 100
c. Name of the Passenger should be string (no numeric digits) of maximum length 20.
<body>
<h1 style="text-align: center;">REGISTRATION FORM</h1>
<form name="RegForm" onsubmit="return GEEKFORGEEKS()" method="post">
<br />
<br />
<br />
<br />
<p>
SELECT YOUR COURSE
<select type="text" value="" name="Subject">
<option>BTECH</option>
<option>BBA</option>
<option>BCA</option>
<option>B.COM</option>
<option>GEEKFORGEEKS</option>
</select>
</p>
<br />
<br />
<p>
<input type="submit"
value="send" name="Submit" />
<input type="reset"
value="Reset" name="Reset" />
</p>
</form>
</body>
<script>
function GEEKFORGEEKS() {
var name =
document.forms.RegForm.Name.value;
var email =
document.forms.RegForm.EMail.value;
var phone =
document.forms.RegForm.Telephone.value;
var what =
document.forms.RegForm.Subject.value;
var password =
document.forms.RegForm.Password.value;
var address =
document.forms.RegForm.Address.value;
var regEmail=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/g; //Javascript reGex for Email
Validation.
var regPhone=/^\d{10}$/; // Javascript reGex for Phone Number validation.
var regName = /\d+$/g; // Javascript reGex for Name validation
if (password == "") {
alert("Please enter your password");
password.focus();
return false;
}
if(password.length <6){
alert("Password should be atleast 6 character long");
password.focus();
return false;
}
if (phone == "" || !regPhone.test(phone)) {
alert("Please enter valid phone number.");
phone.focus();
return false;
}
if (what.selectedIndex == -1) {
alert("Please enter your course.");
what.focus();
return false;
}
return true;
}
</script>
14. Write a HTML document with JavaScript to count the number of Vowels in a text
typed in a Text Area.
HTML Code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Counts the number of vowels within a string</title>
</head>
<body>
</body>
</html>
JavaScript Code:
function vowel_count(str1)
{
var vowel_list = 'aeiouAEIOU';
var vcount = 0;
}
return vcount;
}
console.log(vowel_count("The quick brown fox"));
15. Explain the use of Request and Response objects in the communication between
the browser and the web server.
The server processes the request and sends a response using a protocol (normally
HTTP). The request is sent from the browser to the web server. The term "server"
technically means nothing but a special piece of software running in a remote
computer to access resources
17. Design a HTML form to find the railway fare from one place to another and also
design a 10x10 symmetric Matrix showing the railway fare between two places in a list
of 10 places.
Write a JSP which serves the form and tells the railway fare.
18. What are the event-handling methods in JavaScript?
Events are signals fired inside the browser window that notify of changes in the browser or
operating system environment. Programmers can create event handler code that will run
when an event fires, allowing web pages to respond appropriately to change.
onmouseover The user moves the mouse over an HTML
element
19. What are the JavaScript objects the events on that are for processing HTML form?
20. List all the codes available in JavaScript for the Date.
The getDate() method returns the day of a date as a number (1-31):
example:
const d = new Date();
d.getDate();
21. What are Servlets?
Servlets are the Java programs that run on the Java-enabled web server or application
server. They are used to handle the request obtained from the webserver, process the
request, produce the response, then send a response back to the webserver.
Properties:
Servlets work on the server-side.
Servlets are capable of handling complex requests obtained from the webserver
23. Design a database web page for Student Tabulation and Result using JSP and
JDBC-ODBC.
Active Template Library (ATL), formerly called ActiveX Template Library) is a Microsoft
program library (set of prepackaged program routines) for use when creating Active Server
Page ( ASP ) code and other ActiveX program component s with C++
27. What are some of the most common uses of applets? What features do they
contain?
Java applets are used to provide interactive features to web applications and can be
executed by browsers for many platforms. They are small, portable Java programs
embedded in HTML pages and can run automatically when the pages are viewed.
Features:
Draggable applets.
Separate JVM
Desktop shortcut
Increased heap size
28. Design a web page and include an applet. Customize the applet for your page.
Include information for users of text-only browsers and for those whose browsers are
not Java-enabled.
An applet is an object whose methods are run under the control of a Web browser. The Web
browser acts as a main() method and calls the applet's methods. The methods are called
when a Web page containing an applet is loaded, or in response to events such as mouse
clicks or menu selections.
Applets do not run by themselves. They are run in the context of a Web browser or the
appletviewer of the JDK.
To include an applet on a Web page use the following set of tags:
<applet code="MyApplet.class" width="250" height="200">
</applet>
The width and height give the size of a rectangle in the Web browsers screen that will be
used for the applet. You cannot omit width and height; but you can pick any reasonable
values you want.
The code="MyApplet.class" part names the compiled bytecodes of the applet that will be run.
With the above form of the applet tag, the bytecodes must be in the same disk subdirectory
as the Web page.
29. Design a Web page that uses the onMouseOver and onMouseOut event handlers
to load a new image when a user mouse over an image, and to restore the image
when the user moves the mouse off the image.
function handler(event) {
function str(el) {
if (!el) return "null"
return el.className || el.tagName;
}
if (event.type == 'mouseover') {
event.target.style.background = 'pink'
}
if (event.type == 'mouseout') {
event.target.style.background = ''
}
}
30. Design a Dynamic Web Site for online shopping. Web pages should include HTML,
Fast API, Session Tracking, Cookies, Java script, and DB Connectivity etc.
33. What are the JavaScript events objects for processing HTML form?
JavaScript Event Handlers
Event handlers can be used to handle and verify user input, user actions, and browser
actions:
onmouseout The user moves the mouse away from an HTML element
35. Write the differences between GET and POST methods in Fast API.
Compare GET vs. POST
The following table compares the two HTTP methods: GET and POST.
GET POST
Restrictions on data length Yes, when sending data, the GET No restrictions
method adds the data to the URL;
and the length of a URL is limited
(maximum URL length is 2048
characters)
Restrictions on data type Only ASCII characters allowed No restrictions. Binary data
is also allowed
Security GET is less secure compared to POST is a little safer than
POST because data sent is part GET because the
of the URL parameters are not
stored in browser history
or in web server logs
37. Explain the use of Request and Response objects in the communication between
the browser and the
Fast API web server.
38. Write the importance of integrating Fast API and AJAX with the help of examples.
39. Write a server-side python code to validate the form consisting of a username,
password and email fields.
import re
def solve(s):
pat = "^[a-zA-Z0-9-_]+@[a-zA-Z0-9]+\.[a-z]{1,3}$"
if re.match(pat,s):
return True
return False
from fastapi
import FastAPI,
Form
app = FastAPI()
@app.post("/register")
@app.post("/login")