Sie sind auf Seite 1von 19

Page |1

1. Explain GET and POST method.

The GET Method The foundation of HTTP/0.9 was the definition of the GET method that was used by a web browser to request a specific document. For example, the following HTTP request would return the document index.html that was located in the web servers root directory called webdocs. GET /webdocs/index.html CRLF The Post Method The POST method allows web browsers to send an unlimited amount of data to a web server by allowing them to tag it on to an HTTP request after the request headers as the message body. Example:POST /cgi-bin/phone_book.cgi HTTP/1.0 Referer: http://www.somedomain.com/Direcory/file.html User-Agent: Mozilla/1.22 (Windows: I: 32bit) Accept */* Content-type: application/x-www-form-urlencoded Content-length: 29 name=Selena+Sol&phone=7700404 2. What is HTML? What is the use of HTML? HTML (Hyper Text Markup Language) is a very simple language used to describe the logical structure of a document. Actually, though HTML is often called a programming language it is really not. HTML is simply a markup language used to define a logical structure rather than compute anything. HTML is used for a variety of purposes. It is generic enough that it can be read and interpreted by a web browser running on any machine or operating system as it only focuses on describing the logical nature of the document, not on the specific style. Through HTML tags we can not only define a formatting option but also define attributes as well. 3. Explain document object model. The Document Object Model, or DOM, is the interface that allows us to programmatically access and manipulate the contents of a web page (or document). It provides a structured, object-oriented representation of the individual elements and content in a page with methods for retrieving and setting the properties of those objects. It also provides methods for adding and removing such objects, allowing you to create dynamic content. The DOM also provides an interface for dealing with events, allowing us to capture and respond to user or browser actions. 4. Describe the role of deployment descriptors. A deployment descriptor (DD) refers to a configuration file for an artifact that is deployed to some container/engine. It directs a deployment tool to deploy a module or application with specific container options, security settings and describes specific configuration requirements. XML is used for the syntax of these deployment descriptor files. For web applications, the deployment descriptor must be called web.xml and must reside in the WEB-INF directory in the web application root. 5. What is JSP? What is the use of JSP? Java Server Pages is a technology for developing web pages that include dynamic content. Unlike a plain HTML page, which contains static content that always remains the same, a JSP page can change its content based on any number of variable items, including the identity of the user, the users browser type, information provided by the user, and selections made by the user. What is the difference between web server and application server? Web Server Application Server Does not support EJB(Enterprise Java Beans) Supports EJB Supports database connection pooling It doesnt support database connection pooling Doesnt allow the users to view business logic Allows the users to view business logic It is the software responsible for accepting browser requests, It is a superset of webservers retrieving the specified file (or executing the specified CGI script), and returning its contents (or the scripts results). 6.

Page |2

7. Explain how HTTP is used in client - server system. Client/server system is a way of distributing information across information systems like a local area network (LAN), a wide area network (WAN), or the Internet. A server contains a bunch of files that people might want access to. This server computer runs a software package that listens all day long to requests over the wires. When a request is received for a file, the server software will then access the server hardware, finds the requested file, send it back over the wires to the client who requested it, and then wait for another request from the same or another client. Usually, the client is actually a software program, like Netscape Navigator, that is being operated by a person who is the one who really wants to see the file. So web is a huge client/server system, which uses HTTP (Hyper Text Transport Protocol) as the communicating language between the server and the client. 8. Explain any four HTML tags with examples. Also give attributes. The <BODY> tag represents the body of an HTML page and contains the content to be displayed in the browser window. It has various attributes including: BACKGROUND: Specifies an image to be displayed in the background of an HTML page. Its value can be an absolute URL or a relative URL. BGCOLOR: Sets the color of the background. TEXT: Sets the default color of normal text for the HTML page. LINK: Sets the default color of unvisited links in an HTML page. Syntax:<BODY BACKGROUND="bgURL" BGCOLOR="color" TEXT="color" LINK="color" ALINK="color" VLINK="color" ONLOAD="loadJScode" ONUNLOAD="unloadJScode" ONBLUR="blurJScode" ONFOCUS="focusJScode" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" > ... </BODY> The <TABLE> tag is used to create tables in HTML pages. It has various attributes such as: BORDER: Indicates the thickness, in pixels, of the border to be drawn around the table. CELLPADDING: Determines the amount of space, in pixels, between individual cells in a table. CEPPSPACING: Determines the amount of space, in pixels, between individual cells in a table. WIDTH: Determines the width of the table. Example:<TABLE BORDER CELLPADDING="8" CELLSPACING="4" BGCOLOR=yellow> <TR><TH> English </TH><TH> Spanish </TH><TH> German </TH></TR> <TR><TD> one </TD><TD> uno </TD><TD> ein </TD></TR> <TR><TD> two </TD><TD> dos </TD><TD> zwei </TD></TR> <TR><TD> three </TD><TD> tres </TD><TD> drei </TD></TR> <CAPTION ALIGN="BOTTOM"> <B>Table 1</B>: Tables are as easy as one, two, three </CAPTION> </TABLE> The <IMG> tag inserts images in an HTML page. It has various attributes such as: SRC: Path of the image to be displayed.

Page |3
ALT: Alternative text to be displayed in case the image cannot be displayed. LOWSRC: Path of a low resolution version of the image. HEIGHT and WIDTH: Specifies the dimensions of the image. Example:<IMG SRC="images/violets.jpg" LOWSRC="images/smviol.gif" HEIGHT=180 WIDTH=120 ALT="violets"> The <HR> tag is used to draw a horizontal line in HTML pages. It has various attributes such as: ALIGN: Specifies the horizontal alignment of the lines that do not span the whole page. NOSHADE: Reproduces a solid black line that has no shading. SIZE: Indicates the thickness of the line in pixels. WIDTH: Defines the horizontal width of the line. Example:<P>This text appears above a thick, unshaded, centered horizontal rule. <HR NOSHADE ALIGN="CENTER" WIDTH="50%" SIZE="8"> <P>This text appears below the horizontal rule. 9. Write HTML script to display Hello world, welcome to the world of HTML, the title as world of HTML. <html> <head> </head> <title> Welcome to the world of HTML </title> <body> <i>"Hello World</i><b>Welcome to the world of HTML"</b> </body> </html> 10. What is Java script? What is the use of Java script and what are its disadvantages? What are the advantages of Javascript? JavaScript is an easy-to-learn way to script our web pagesthat is, have them to do actions that cannot be handled with HTML alone. Disadvantages: JavaScript does not have any graphics capabilities, except for the ability to format and display HTML. For security reasons, client-side JavaScript does not allow the reading or writing of files. JavaScript does not support networking of any kind, exceptan important exception, that it can cause a web browser to download the contents of arbitrary URLs. Finally, JavaScript doesnt have any multithreading capabilities, except whatever comes implicitly from the web browsers internal use of threads. Advantages: Control Document Appearance and Content Control the Browser Interact with Document Content Interact with the User Read and Write Client State with Cookies Interact with Applets Manipulate Embedded Images

Page |4
11. Explain briefly about cascading style sheets (CSS). CSS stands for Cascading style sheets and is the part of DHTML that controls the look and placement of the elements on a page. With CSS we can basically set any style property of any element on a HTML page. One of the biggest advantages with CSS instead of the regular way of changing the look of elements (the font tag and similar) is that we split content from design. 12. What is PERL? Explain the different types of PERL variables. Perl is a high-level, general-purpose, interpreted, dynamic programming language. The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary UNIX tools, facilitating easy manipulation of text files. Perl gained widespread popularity in the late 1990s as a CGI scripting language, in part due to its parsing abilities. In addition to CGI, Perl is used for graphics programming, system administration, network programming, finance, bioinformatics, and other applications. Two different types of PERL variables:Scalars A scalar variable stores a single value of any type. Scalar variables are prefixed with a $. These variables need not be declared before using them. You can define or use a variable as: $var =1; $var_noval; $str = "This is a scalar string variable"; Program:- scalar.cgi Print Scalar Variables Program #!/usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; my $email = fnord\@cgi101.com; my $url = http://www.cgi101.com; print header; print start_html(Scalars); print <<EndHTML; <h2>Hello</h2> <p> My e-mail address is $email, and my web url is <a href=$url>$url</a>. </p> EndHTML print end_html; Arrays Arrays store an ordered list of values. Arrays can be declared as: @emptyarr =(); @arr = ("1", "2","3"); Each individual item of an array is referred to by its index number as: print "$arr[0]"; We can use the push() and pop() functions to insert or delete an element from an array. We can print all the values of an array using a foreach loop: my @colors = (red,green,blue); foreach my $i (@colors) { print $i\n; } Hashes A Hash is a special kind of an array - an associative array or paired list of elements. Each pair in a Hash consists of a string key and data value. A hash is defined as: %emptyhs = (); %hs = ("key1", "val1", "key2", "val2"); or %hs = (key1 => "val1",

Page |5
key2=> "val2"); An individual item of a Hash is referred to as $hs{"key1"}; The my function can be used with each of the above type of variables to declare and limit the scope of the variable to the enclosing block as: my $var; Program: colors.cgi - Print Hash Variables Program We can print the Hash variables by using Perls qq operator: print qq(<font color=$colors{$colors}>$color</font>\n); qq creates a double-quoted string for us. 13. Write a simple CGI application which accepts the user information and displays the information entered to the user. #!/perl/bin/perl -wT print Content-type: text/html\n\n; print Hello, world!\n; The first line of your program should look like this: #!/perl/bin/perl wT 14. What are the approaches that the web application can be deployed in Tomcat. A web application can be deployed in Tomcat by one of the following approaches: Copy unpacked directory hierarchy into a subdirectory in directory $CATALINA_BASE/webapps/. Tomcat will assign a context path to our application based on the subdirectory name we choose. We will use this technique in the build.xml file that we construct, because it is the quickest and easiest approach during development. Copy the web application archive file into directory $CATALINA_BASE/webapps/. When Tomcat is started, it will automatically expand the web application archive file into its unpacked form, and execute the application that way. This approach would typically be used to install an additional application, provided by a third party vendor or by our internal development staff, into an existing Tomcat installation. Use the Tomcat "Manager" web application to deploy and undeploy web applications. Tomcat includes a web application, deployed by default on context path /manager, that allows us to deploy and undeploy applications on a running Tomcat server without restarting it. Use "Manager" Ant Tasks in our Build Script. Tomcat includes a set of custom task definitions for the Ant build tool that allow us to automate the execution of commands to the "Manager" web application. Use the Tomcat Deployer. Tomcat includes a packaged tool bundling the Ant tasks, and can be used to automatically precompile JSPs which are part of the web application before deployment to the server.

15. Give the high level communication between web browser (client) and web server. The browser breaks the URL into three parts: (Consider http://www.mywebsite.com/firstpage.htm as an example URL) The protocol (http) The server name (www.mywebsite.com) The file name (web-server.htm) The browser communicated with a name server to translate the server name www.mywebsite.com into an IP Address, which it uses to connect to the server machine. The browser then formed a connection to the server at that IP address on port 80. Following the HTTP protocol, the browser sent a GET request to the server, asking for the file http://www.mywebsite.com/firstpage.htm. The server then sent the HTML text for the Web page to the browser. (Cookies may also be sent from server to browser in the header for the page.) The browser read the HTML tags and formatted the page onto your screen.

Page |6
16. Briefly explain the three types of JSP elements that we use. Give an example. Or With the help of an example explain JSP elements. There are three types of JSP elements you can use: directive, action, and scripting. Directive elements The directive elements specify information about the page itself that remains the same between requests. Element Description <%@ page ... %> Defines page-dependent attributes, such as session tracking, error page, and buffering requirements <%@ include ...%> Includes a file during the translation phase <%@ taglib ...%> Declares a tag library, containing custom actions, that is used in the page Standard action elements Action elements typically perform some action based on information that is required at the exact time the JSP page is requested by a browser. Element Description <jsp:useBean> Makes a JavaBeans component available in a page <jsp:getProperty> Gets a property value from a JavaBeans component and adds it to the response <jsp:setProperty> Sets a JavaBeans component property value <jsp:include> <jsp:forward> <jsp:param> <jsp:plugin> Includes the response from a servlet or a JSP page during the request processing phase Forwards the processing of request to a servlet or JSP page Adds a parameter value to a request handed off to another servlet or JSP page using <jsp:include> or jsp:forward> Generates HTML that contains the appropriate browserdependent elements (OBJECT or EMBED) needed to execute an applet with the Java Plug-in software

Scripting elements Scripting elements allows us to add small pieces of code in a JSP page. Element Description <% ...%> Scriptlet, used to embed scripting code. <%= Expression, used to embed scripting code expressions when the ...%> result shall be added to the response. Also used as request-time action attribute values. <%! ...%> Declaration, used to declare instance variables and methods in the JSP page implementation class.

Page |7

17. What are the advantages of JSP? Advantages of JSP are: JSP supports both scripting- and element-based dynamic content and allows programmers to develop custom tag libraries to satisfy application-specific needs. JSP pages are compiled for efficient server processing. JSP pages can be used in combination with servlets that handle the business logic. JSP is a specification, not a product. This means vendors can compete with different implementations, leading to better performance and quality. JSP is an integral part of J2EE, a complete platform for enterprise class applications. This means that JSP can play a part in the simplest applications to the most complex and demanding. 18. What is servlets? Give the Basic servlet structure / Explain with an example. Servlets are Java technologys answer to CGI programming. They are programs that run on a Web server and build Web pages. Basic servlet structure:import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SomeServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Use "request" to read incoming HTTP headers (e.g. cookies) // and HTML form data (e.g. data the user entered and submitted) // Use "response" to specify the HTTP response line and headers // (e.g. specifying the content type, setting cookies). PrintWriter out = response.getWriter(); // Use "out" to send content to browser } }

Page |8
19. With diagram explain the life cycle of a servlet. Life cycle of a servlet

20. What are cookies? Explain in brief. A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is usually a small piece of data sent from a website and stored in a user's web browser while a user is browsing a website. When the user browses the same website in the future, the data stored in the cookie can be retrieved by the website to notify the website of the user's previous activity. Cookies were designed to be a reliable mechanism for websites to remember the state of the website or activity the user had taken in the past. This can include clicking particular buttons, logging in, or a record of which pages were visited by the user even months or years ago. 21. What is the difference between sessions and application? Application scope is the broadest. We can create objects bound at application level in JSPs that are not session-aware, so application scope is useful for storing information when using these types of JSPs. We can also use application-bound objects to share data among different sessions of the same application. When you no longer need objects bound to an application, we should explicitly remove them to free up memory resources. Session scope is more commonly used than application scope. Session scope allows us to create and bind objects to a session. We must create objects bound to the session in session-aware JSPs and make them available to all JSPs and servlets in the same session. Session scope is often used for managing security credentials and for managing state among multiple pages. 22. What are EJBs? What are the advantages and disadvantages of EJBs. An EJB is a server-side component that executes specific business logic. EJBs run on a server and are invoked by local or remote clients. A standardized contract exists between an application server and its EJB components that enable a component to run within any application server. The application server provides clearly-defined services while the components adhere to a standard interface. EJBs are not GUI components; rather, they sit behind the GUIs and perform all the business logic. GUIs such as rich clients, web-based clients, and web services are the clients that can make connections to EJBs. Advantages of EJB Many vendor application servers conform to the J2EE specification allowing one to select a best-of-breed solution. To handle fluctuations in resource demand server-side resources can easily be scaled by adding or removing servers. Application servers provide access to complex services, namely transaction and security management, resource pooling, JNDI (Java Naming and Directory Interface), component lifecycle management, etc. Disadvantages of EJB EJB has a large and complicated specification. EJBs take longer to develop. Also, when things go wrong they can be more difficult to debug. Occasionally the bug may not be in our code but in the application server itself.

Page |9
No sooner have we deployed your EJB application than we see a new specification coming down the pipe with newer features, rendering our application obsolete. This situation, however, is unavoidable with cutting-edge technologies.

23. What is web? What are the differences between Internet and Intranet? Explain. The Web is a system of interlinked hypertext documents accessed via the Internet. With a web browser, one can view web pages that may contain text, images, videos, and other multimedia, and navigate between them via hyperlinks. The web was initially conceived and created by Tim Berners-Lee, a computer specialist from the CERN in 1989. The web is a complex, international, cross platform, cross language, cross cultural mesh of servers, clients, users, databases, and quite a few artificial intelligences all talking, working, searching, viewing, accessing and downloading. Internet refers to the world-wide collection of independent networks, connected via routers to each other for communication purposes. Intranet refers to a collection of networks within a logical body, such as a building, corporation or other entity. Intranets can be as simple as two computers connected at home to each other, or as vast as 1000 branch offices of a bank, connected via privately owned, non-public network links. Intranets usually have a firewall and router, which permits access to the public Internet, while protecting the internal Intranet from malicious users. 24. What is a web server? What is the use of it? The Web server is the software responsible for accepting browser requests, retrieving the specified file (or executing the specified CGI script), and returning its contents (or the scripts results). Web servers are often called httpd, using a UNIX convention in which daemons are named with the name of the service followed by the letter d. (A UNIX daemon is a process that sits idle waiting for other programs to make requests.) The most common use of web servers is to host websites, but there are other uses such as gaming, data storage or running enterprise applications. 25. Explain the building elements of WEB. There are certain standards of communication upon which the web is built. These standards sit at a layer above operating systems, computer languages, or Internet transmission protocols and provide a basic medium for communication. The two most important standards (protocols) used on the web today are HTTP and HTML. HTML the Language of the Web HTML (Hyper Text Markup Language) is a very simple language used to describe the logical structure of a document. Actually, though HTML is often called a programming language it is really not. HTML is simply a markup language used to define a logical structure rather than compute anything. HTTP HTTP is a protocol that is defined in several RFCs (Request for Comments) located at the Internic and has had several generations worth of revisions (HTTP/09, HTTP/1.0 and HTTP/1.1). HTTP is a request-response type protocol that specifies that a client will open a connection to a server then send a request using a very specific format. The server will then respond and close the connection. HTTP is a language spoken between our web browser (client software) and a web server (server software) so that they can communicate with each other and exchange files. 26. Write an HTML program to demonstrate applet embedding. <Html> <Head> <Title>Java Example</Title> </Head> <Body> This is my page<br> Below you see an applet<br> <br> <Applet Code="MyApplet.class" width=200 Height=100> </Applet> </Body> </Html>

P a g e | 10
27. Explain ordered lists and unordered lists. OL (ordered list) The OL tag displays an ordered, or numbered, list. Syntax: <OL START="value" TYPE="A"|"a"|"I"|"i"|"1" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" > ... </OL> START=value Example:<P>The following steps outline how to create HTML files:</P> <OL START="3" TYPE="I"> <LI> Use a text editor or Netscape Composer to create your HTML file. <LI> Put the HTML files on a web server. <LI> Test the files by viewing them in a web browser. </OL> UL (unordered list) The UL tag displays a bulleted list. Syntax <UL TYPE="CIRCLE"|"DISC"|"SQUARE" CLASS="styleClass" ID="namedPlaceOrStyle" LANG="ISO" STYLE="style" > Example <P>Netscape Composer offers the following benefits</P> <UL TYPE=SQUARE> Edit web pages directly in Navigator Easy options for setting background and link colors As easy to use as any text editor No need to learn HTML </UL> 28. What is extra path information? Explain with an example. Besides passing query information to a CGI script, you can also pass additional data, known as extra path information, as part of the URL. The server gauges where the CGI program name ends; anything following is deemed extra and is stored in the environment variable PATH_INFO. The following line calls a script with extra path information: http://some.machine/cgi-bin/display.pl/cgi/cgi_doc.txt Since the server knows that display.pl is the name of the program, the string /cgi/cgi_doc.txt is stored in the environment variable PATH_INFO. Meanwhile, the variable PATH_TRANSLATED is also set, which maps the information stored in PATH_INFO to the document root directory (e.g., /usr/local/ etc/httpd/ public/cgi/cgi-doc.txt in case of UNIX OS). 29. Compare JSP with CGI programming. JSP stands for JAVA SERVER PAGES, whereas CGI stands for COMMON GATEWAY INTERFACE. In CGI, whenever a multiple requests of the same dynamic web page is made by the client to the server, a new process is created of the corresponding CGI program, for each and every request generated as such this is not the case in JSP. In JSP, when the first

P a g e | 11
request is made for a dynamic web page. Its corresponding class file and hence the servlet is then cached in the memory, and hence new threads are generated for the further requests made, saving resources. 30. Explain implicit objects out, request, and response in a JSP page. As a JSP author, we have implicit access to certain objects that are available for use in all JSP documents. These objects are parsed by the JSP engine and inserted into the generated servlet as if we defined them ourselves. out The implicit out object represents a JspWriter (derived from a java.io.Writer) that provides a stream back to the requesting client. The most common method of this object is out.println(), which prints text that will be displayed in the clients browser. request The implicit request object represents the javax.servlet.http.HttpServletRequest interface. The request object is associated with every HTTP request. response The implicit response object represents the javax.servlet.http.HttpServletResponse object. The response object is used to pass data back to the requesting client. 31. Outline the main steps in implementing a servlet. Following are the steps used in implementing a servlet for HTTP communication: Import required servlet packages in the class. Make the class extend HttpServlet. Override methods doGet(), doPost(), or doService() as required by problem in hand. Make an entry for the above servlet in deployment descriptor. Configure any extra options or filters, which are required by the server to function. 32. What are hidden controls? List the advantages of hidden controls. Some fields in the HTML code are marked as hidden. Such fields are ignored when a visual representation is created. However they are submitted to the server along with all the other data. These are hidden controls. Advantages of hidden controls: Using hidden controls in a Web page is the easiest way of associating some information with the user thats not directly accessible to him. It can uniquely identify different database records. 33. Write short notes on : a) SSL b) XML SSL:The Secure Sockets Layer (SSL) protocol, originally developed by Netscape, has become the universal standard on the Web for authenticating Web sites to Web browser users, and for encrypting communications between browser users and Web servers. The main role of SSL is to provide security for Web traffic. Security includes confidentiality, message integrity, and authentication. SSL achieves these elements of security through the use of cryptography, digital signatures, and certificates. SSL encrypts the segments of network connections at the Transport Layer, using asymmetric cryptography for key exchange, symmetric encryption for privacy, and message authentication codes for message integrity. XML:XML or the Extensible Markup Language provides a portable language for describing data. XML is a simple, common format for representing structured information as text. The concept of XML follows the success of HTML as a universal document presentation format and generalizes it to handle any kind of data. In the process, XML has not only recast HTML but is transforming the way that businesses think about their information. It defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The design goals of XML emphasize simplicity, generality, and usability over the Internet. Although the design of XML focuses on documents, it is widely used for the representation of arbitrary data structures, for example in web services. 34. List the different classification of HTML tags with an example of each. The different classifications of HTML tags are: Tags for Document Structure (eg. HTML) Heading Tags (eg. TITLE) Block-Level Text Elements (eg. ADDRESS)

P a g e | 12
Lists (eg. DD) Text Characteristics (eg. B)

35. Why we require Java script and DHTML? Every time when user requests querying Server and getting information from server is a very slow process. Also, some actions like verifying whether user has entered all the fields or user has entered only digits, not characters can be verified at the Client Side only. For this some programming support should be provided. For doing this we use Java Script. Though JavaScript contains the name java, they are not same. While Java can be used to make standalone applets (like a regular programming language), JavaScript is generally only used inside of HTML documents. DHTML stands for Dynamic Hyper Text Markup Language. DHTML is combination of Web Technologies which can be basically used to set the properties of Web Pages and its look and feel. 36. Create a simple HTML page to demonstrate the usage of anchor tags. The following HTML page, demonstrates the usage of anchor tags: <html> <head> <title>Anchor Tag Characteristics</title> </head> <body> <h1 align="center">All in One</h1> <p align="left">In <A HREF= "#sec1">section 1</a> you can search. In <A HREF= "#sec2">section 2</a> you can shop.</p> <A NAME= "sec1">Section 1: </a> <p> <a href="http://google.co.in" target= "_blank"> Search on Google</a>&nbsp;</p> <p><a href="http://yahoo.com">Search on Yahoo</a></p> <p>&nbsp;</p> <p> <A NAME= "sec2">Section 2: </a> </p> <p><a href="http://ebay.com"> Shop on ebay&nbsp;</a></p> <p><a href="http://wallpapers.com">Download wallpapers</a>&nbsp;</p> <p><a href="http://t-shirts.com"> Order Custom T-Shirts News</a></p> </body> </html> 37. Explain the methods to access nodes in a document tree. Following are the methods used to access a node in a document tree: document.getElementById(): Returns the element or node whose ID is passed as a parameter to it. document.getElementsByTagName(): Returns the list of nodes that have the tag passed to the function as a parameter. 38. Explain any five CGI environment variables. Also give an example. When a CGI program is called, the information that is made available to it can be roughly broken into three groups: Information about the client, server, and user Form data that the user supplied Additional pathname information Most information about the client, server, or user is placed in CGI environment variables. Form data is either incorporated into an environment variable, or is included in the body of the request. Environment variable Description HTTP_REFERER The URL of the document that the client points to before accessing the CGI program REMOTE_USER The authenticated name of the user

P a g e | 13
AUTH_TYPE The authentication method used to validate a user REMOTE_HOST The remote hostname of the user making the request REQUEST_METHOD The method with which the information request was issued Program: envvar.cgi - Print environment variables #!/usr/local/bin/perl print "Content-type: text/html", "\n\n"; print "<HTML>", "\n"; print "<HEAD><TITLE>About this Server</TITLE></HEAD>", "\n"; print "<BODY><H1>About this Server</H1>", "\n"; print "<HR><PRE>"; print "Server Name: ", $ENV{'SERVER_NAME'}, "<BR>", "\n"; print "Running on Port: ", $ENV{'SERVER_PORT'}, "<BR>", "\n"; print "Server Software: ", $ENV{'SERVER_SOFTWARE'}, "<BR>", "\n"; print "Server Protocol: ", $ENV{'SERVER_PROTOCOL'}, "<BR>", "\n"; print "CGI Revision: ", $ENV{'GATEWAY_INTERFACE'}, "<BR>", "\n"; print "<HR></PRE>", "\n"; print "</BODY></HTML>", "\n"; exit (0); 39. With the help of an example explain Query String. One way to send form data to a CGI program is by appending the form information to the URL, after a question mark. The information after the ? character is known as a query string. When the server is passed a URL with a query string, it calls the CGI program identified in the first part of the URL (before the ?) and then stores the part after the ? in the environment variable QUERY_STRING. The following is a CGI program called name.pl that uses QUERY_STRING to print the information passed. http://some.machine/cgi-bin/name.pl?fortune #!/usr/local/bin/perl print Content-type: text/plain, \n\n; $query_string = $ENV{QUERY_STRING}; if ($query_string eq fortune) { print query string is fortune; } elsif ($query_string eq finger) { print query string is finger; } else { print invalid query string; } exit (0); 40. Explain how servlet mapping are done in web.xml. Servlet Mapping is done in Web.xml with the help of the <servlet_mapping> tag as: <servlet-mapping> <servlet-name>Controller</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>graph</servlet-name> <url-pattern>/graph</url-pattern> </servlet-mapping> According to the first mapping, all requests of the form http://localshots:8080/{contextpath}.do will be mapped to the Controller servlet whereas according to second mapping all request of the form http://localshots:8080/{contextpath}/graph will be mapped to the graph servlet. 41. Write a JSP program which displays different message to the user based on the time of day. <%@ taglib prefix=c uri=http://java.sun.com/jstl/core %> <html> <body bgcolor=white> <jsp:useBean id=clock class=java.util.Date /> <c:choose>

P a g e | 14
<c:when test=${clock.hours < 12}> <h1>Good morning!</h1> </c:when> <c:when test=${clock.hours < 18}> <h1>Good day!</h1> </c:when> <c:otherwise> <h1>Good evening!</h1> </c:otherwise> </c:choose> Welcome to our site, open 24 hours a day. </body> </html> 42. Describe the request handling cycle, and the methods invoked on the servlet by the servlet container. Following are the operations done on a servlet by servlet container when a servlet is requested: If servlet instance does not exist in memory, the container: Loads the servlet class and thus creates its instance Calls the init() method on the above class and passes ServletConfig as parameter On any further request service() method of servlet class is called and HttpServletRequest and HttpServletResponse are passed as parameters to it. 43. What are sessions? Explain in brief how to track a user using sessions with an example. Sessions are something the server offers us to support user tracking, although they can take up a lot of resources on the server. Sessions let us preserve data between accesses to a Web page by the same user. The HTTP protocol is by its very nature statelessthat is, when we load a page a number of times in succession, the server start anew each time. Session tracking is a mechanism that is used to maintain state about a series of requests from the same user(that is, requests originating from the same browser) across some period of time. A session id is a unique token number assigned to a specific user for the duration of that user's session. Example: session_track_jsp.jsp <!--session declaration makes the session implicit variable available to a JSP page.--> <%@page import = "java.util.*" session="true"%> <HTML> <HEAD> <TITLE>Using Sessions to Track Users through JSP Code</TITLE> </HEAD> <BODY bgcolor="#084B8A"> <font size="+3" color="#E6E6E6"><br>track user using session</font> <TABLE style="background-color: #CEF6F5;" border="1"> <% /* here if counter has not been set before, getAttribute will return a value of null. That means you can create the counter value, or increment it if it already exists, and store the new value in the session object*/ Integer counter = (Integer)session.getAttribute("counter"); if (counter == null) { counter = 1; } else {

P a g e | 15
counter = counter+1; } /* setAttribute() binds counter value to this session, using the specified name here "counte".*/ session.setAttribute("counter", counter); %> <!-- use getId() method to get a unique session id --> <tr><th>Session ID</th><td><%=session.getId()%></td></tr> <!-- getCreationTime() method returns date and time when session was created --> <tr><th>Session creation time</th><td><%=new Date(session.getCreationTime())%></td></tr> <!--getlastAcccessTime() method returns date and time of last access by this session id--> <tr><th>Last accessed time</th><td><%=new Date(session.getLastAccessedTime())%></td></tr> <!-- this counter variable will print how much time user visited in application --> <tr><th>visited</th><td><%=counter%> times</td></tr> </BODY> </HTML> 44. Write the difference between HTML and DHTML. HTML Is a language It is referred as a static HTML and static in nature. A plain page without any styles and Scripts called as HTML. HTML sites will be slow upon client-side technologies.

DHTML Is a technology It is referred as a dynamic HTML and dynamic in nature. A page with HTML, CSS, DOM and Scripts called as DHTML. DHTML sites will be fast enough upon client-side technologies.

45. How are JSPs better than servlets? JSPs are better than servlets in the following ways: It is more convenient to write (and to modify) regular HTML than to have a zillion println statements that generate the HTML. By separating the look from the content we can put different people on different tasks: our Web page design experts can build the HTML, leaving places for our servlet programmers to insert the dynamic content. 46. Explain in detail the role played by CGI programming in web programming. CGI stands for Common Gateway Interface. It is the standard method by which values are passed between the client to the server and vice-versa. This takes the form of a request and a reply. Through this mechanism, input can be received through an HTML form and processed by a program on the web server. In the context of web programming, CGI is basically a set of rules for executing programs on the web server. These programs are given sufficient access to the server's file system and resources to be able to do things like write to databases, retrieve information etc. 47. Explain the usage of script tags. The following example uses the SCRIPT tag to define a JavaScript script in the HEAD tag. The script is loaded before anything else in the document is loaded. <HTML> <HEAD><TITLE>Script Example</TITLE> </HEAD> <SCRIPT language="JavaScript"> function changeBGColor (newcolor) { document.bgColor=newcolor; return false; } </SCRIPT>

P a g e | 16
<BODY > <P>Select a background color:</P> <FORM> <INPUT TYPE="button" VALUE=blue onClick="changeBGColor('blue');"> <INPUT TYPE="button" VALUE=green onClick="changeBGColor('green');"> </FORM> <NOSCRIPT><I>Your browser is not JavaScript-enabled. These buttons will not work.</I> </NOSCRIPT> 48. What is a war file? Explain its importance. A web application is defined as a hierarchy of directories and files in a standard layout. Such a hierarchy can be accessed in its unpacked form, where each directory and file exists in the file system separately, or in a packed form known as a Web ARchive, or WAR file. In addition to Web components, a Web application archive usually contains other files, including the following: Server-side utility classes. Static Web content. Client-side classes. Advantages of WAR files: easy development, testing and deployment the version of the deployed application is easily identified all J2EE containers support .WAR files 49. Write an example HTML page containing a table 4 X 3 and each row colored differently. The following is an HTML page containing a table 4 X 3 and each row colored differently: <html> <head> <title>Colored Table</title> </head> <body> <table border="1" width="100%"> <tr bgcolor="#0000FF"> <td width="33%">&nbsp;</td> <td width="33%">&nbsp;</td> <td width="34%">&nbsp;</td> </tr> <tr bgcolor="#00A0FF"> <td width="33%">&nbsp;</td> <td width="33%">&nbsp;</td> <td width="34%">&nbsp;</td> </tr> <tr bgcolor="#AB00FF"> <td width="33%">&nbsp;</td> <td width="33%">&nbsp;</td> <td width="34%">&nbsp;</td> </tr> <tr bgcolor="#FB2CFF"> <td width="33%">&nbsp;</td> <td width="33%">&nbsp;</td> <td width="34%">&nbsp;</td> </tr> </table> </body> </html>

P a g e | 17
50. Explain how you can embed an image in an HTML page. To embed an image in an HTML page, you can use the <IMG> tag. The <IMG> tag includes various attributes, for embedding and formatting images in an HTML page. The most common attributes of the <IMG> tag are: SRC: Absolute or relative path of the image to be embedded LOWSRC: The path of the low resolution version the image ALT: Alternate text to be displayed in case the image cannot be loaded. ALIGN : Alignment of the image in the page HEIGHT: Height of the image WIDTH: Width of the image We can use the above tags to load an image from a URL or a relative path. For example, if the image (suppose image_filename.gif) that you want to embed resides in the same folder as the HTML page, we can embed it as: <IMG SRC="image_filename.gif" ALT = "this is an image loaded from a relative path"> The above will display the image in the file image_filename.gif. In case this image cannot be loaded, the text "this is an image loaded from a relative path" will be displayed. 51. Explain CGI.pm module with an example. PERL supports various add-on modules, which are libraries of functions that perform specific tasks. These are called standard library modules. CGI.pm is a standard library module, which provides various functions. To include the CGI.pm module in our PERL script, we have to use the "use" command after the #!/perl/bin/perl line and before any other code: use CGI qw(:standard); After including CGI.pm we can call its functions such as header, which prints the Content-type header. 52. Write a CGI application that accepts 3 numbers from the users and displays the LCM of three numbers using GET and POST methods. #!/usr/bin/perl #print "Content-type:text/html\n\n"; #$form = $ENV{'QUERY_STRING'}; use CGI; $cgi = new CGI; print $cgi->header; print $cgi->start_html( "Question Ten" ); my $one = $cgi->param( 'one' ); my $two = $cgi->param( 'two' ); my $three = $cgi->param( 'three' ); if( $one && $two && $three ) { $lcm = &findLCM( &findLCM( $one, $two ), $three ); print "LCM is $lcm"; } else { print '<form action="ques10.pl" method="post"><pre>'; print 'Enter First Number <input type="text" name="one"><br>'; print 'Enter Second Number <input type="text" name="two"><br>'; print 'Enter Third Number <input type="text" name="three"><br>'; print '<input type="submit" value="Submit"><br>'; print "</pre></form>"; } print $cgi->end_html; sub findLCM() { my $x = shift; my $y = shift; my $temp, $ans;

P a g e | 18
if ($x < $y) { $temp = $y; $y = $x; $x = $temp; } $ans = $y; $temp = 1; while ($ans % $x) { $ans = $y * $temp; $temp++ ; } return $ans; } 53. Draw a class diagram to show the relationships between the major classes in the servlet API. The class diagram is shown here:-

54. Explain the semantics of the HTML FORM element. The HTML form element represents a form in which users can input data and submit it to the server for processing. The HTML form tag is as follows: <FORM NAME="name" ACTION = "action.jsp" METHOD = "POST/GET"> The name attribute specified the name for a form. The action attribute specified the URL of the document or the name of the file to which the form data is submitted for action and the method attribute specified the HTTP method through which the data is sent to the server. The action attribute can be a simple static Web page or a servlet. The method can be POST or GET. A form includes various other <INPUT> elements such as textbox, list, buttons, or checkboxes. 55. Explain in brief how to use hidden controls in a web page? Give an example. Using HTML, hidden controls are an easy way to store data in a Web page. We can store data in a hidden control and then refer to the value of control wherever required. Hidden controls are often used when we submit a form to itself. That is if our form's ACTION attribute is set to the same page which contains the form. In this case, every time the page loads we have to determine whether it is

P a g e | 19
being loaded afresh or after a submission. For this, we can store a text value such as "DONE" in a hidden control SUBMIT_STATUS, and check for it whenever the page loads. If request.getParameter(SUBMIT_STATUS) returns a NULL value, it means that the form is being loaded afresh. This logic is demonstrated in the following code: <html> <head></head> <body> <% if(request.getParameter("DONE")==null) { out.println("You entered your name as:" + getParameter("name")); } else { %> <form action = "this.jsp" method = "POST"> Enter your name:<input type ="text" name = "name"></input <input type = "HIDDEN" name = "DONE" value ="submitted"> <input type = "SUBMIT" value = "SUBMIT"> </form> <% } %> </body> </html> 56. What are the disadvantages of hidden controls? The disadvantages of hidden controls are that they are not secure as any user can access the HTML source and view their value. Consequently, you cannot store crucial information such as passwords in them. In addition, they complicate the code many times. 57. List down any 6 methods of javax.servlet.http.Cookie class and their functionality. Following are the methods of the Cookie class: java.lang.String getName(): Returns the name of the cookie java.lang.String getValue(): Returns the value of the cookie void setValue(java.lang.String value): Assigns a new value to a cookie after it has been created void setPath(java.lang.String uri): Sets the path for the cookie by which the browser will send the cookie void setMaxAge(int expiry): Set the maximum age of the cookie in seconds int getMaxAge(): Returns the maximum age of the cookie in second 58. List down any 6 methods of HttpServletResponse class and their functionality. Following are the methods of the HttpServletResponse class: int SC_ACCEPTED: Indicates that a request was accepted for processing but was not completed int SC_BAD_GATEWAY: Indicates that the HTTP server received an invalid response from a server, when acting as a proxy or gateway int SC_BAD_REQUEST: Indicates that the request sent by the client was incorrect int SC_CONFLICT: Indicates that the request cannot be completed because of a conflict with the current state of the resource int SC_CONTINUE: Indicates that the client can continue 59. Discuss the difference between static and dynamic Web pages? Static Web pages are not processed by the server and are sent as it is. These pages do not have any scripting logic and they cannot change according to client's request parameters. Dynamic Web pages are processed by the server and then the generated content is sent to the client. They may involve information from a database or some other information such as client's user name.

Das könnte Ihnen auch gefallen