Escolar Documentos
Profissional Documentos
Cultura Documentos
Q40. What is a
element is a text input field in which each webserver? Explain.
character typed is displayed as a character such as * or Ans: The Web server is software. It is responsible for
a black dot to conceal the actual value. accepting browser requests,
retrieving the specified file, and returning its contents. Q42. Explain any three method of the
Web servers first retrieve the javax.servlet.http.HttpSession interface.
request using Berkeley sockets. The Web server listens Ans. a) void addCookie(Cookie cookie): -Adds the
for requests on a particular specified cookie to the response object
port on the server machine. Once the b) java.util.Enumeration getAttributeNames():
server receives the request, it locates the -Returns Java Enumeration of String objects containing
document being requested. It looks for the the names of all the objects in this session.
file under the document root directory. c) long getCreationTime(): -Returns the time when
The server sends the contents of the file this session was created (measured in
back to the client. By default web browsers milliseconds since midnight January 1, 1970 GMT).
use port no. 80 for their requests. Once the d) long getLastAccessedTime(): -Returns the last time
server receives the request, it locates the the client sent a request in
document being requested. It looks for the with this session, as the number of milliseconds since
file under the document root directory. For example, if midnight January 1, 1970 GMT.
the document root is /usr/local/httpd/htdocs, e) int getMaxInactiveInterval(): - Returns the
and the client requests the document maximum time, in seconds, which the
/staff/matthew.html, then the server retrieves server will keep this session open between client
/usr/local/httpd/ accesses.
htdocs/staff/ matthew.html.The server sends the f) void removeAttribute(java.lang.String name):
contents of the file back to the client, along with some -Removes the object with
HTTP response headers. Among the data in the the specified name from this session.
response headers is the media type (also known as a
content type or MIME type), i.e., the format that the file Q43. What do you mean by scriptlets in JSP?
is in. Ans: Scriptlets are the JSP components that bring all
the JSP elements together.
Q41.Explain JSP error handling. They can contain almost any coding statements that are
Ans: Like all development methods, JSPs need a valid for the language
dynamic mechanism for handling errors. referenced in the language directive. They are executed
The JSP architecture provides an error-handling at request time, and they
solution through the use of JSPs that are can make use of all the JSP components. The syntax
written exclusively to handle JSP errors. The errors that for a scriptlet is as follows:
occur most frequently are runtime <% scriptlet source %>
errors that can arise either in the body of the JSP page
or in some other object that is called Q44.What is SSL? What is the necessity of it?
from the body of the JSP page. Request-time errors that Explain the working of SSL.
result in an exception being thrown Ans: SSL stands
can be caught and handled in the body of the calling for
JSP, which signals the end of the error. Secure Sockets
Exceptions that are not handled in the calling JSP result Layer.
in the forwarding of the client request, SSL is a protocol.
including the uncaught exception, to an error page It is developed by
specified by the offending JSP. Here we Netscape, has become the
see how an error page works, let’s create a simple JSP universal standard on the
that throws an uncaught exception. Web for authenticating
The JSP shown here uses the error page created in the Web sites to Web browser
previous section. users, and for encrypting
<%@ page errorPage=”errorpage.jsp” %><%if ( true ) communications between browser users and Web
{ throw new Exception(“An uncaught servers. The main role of SSL
Exception”);}%> In this listing that the first line of is to provide security for Web traffic. Security includes
code sets errorPage equal to errorpage.jsp, onfidentiality, message
which is the name of the error page. To make a JSP integrity, and authentication. The working of SSL is:
aware of an error page,we simply need to add the SSL has two distinct entities,
errorPage attribute to the page directive and set its server and client. The client is the entity that initiates
value equal to the location of our JSP error page. the transaction, whereas the
server is the entity that responds to the client and ID="namedPlaceOrStyle" –LANG=”ISO”
negotiates which cipher suites -STYLE=”style” > </OL>.
are used for encryption. In SSL, the Web browser is Unordered list: The UL tag displays a bulleted list.
the client and the Web-site You can use the tag’s TYPE
server is the server. Three protocols lie within SSL, the attribute to change the bullet style. Use the LI tag to
Handshake Protocol, designate the individual list items in the list.
the Record Protocol, and the Alert Protocol. The client Syntax: <UL TYPE="CIRCLE"|"DISC"|"SQUARE"
authenticates the server -CLASS="styleClass" –
during the Handshake Protocol. When the session is ID="namedPlaceOrStyle"—LANG= “ISO”
initiated and the handshake -STYLE=”style” > </UL>.
is complete, the data transfer is encrypted during the
Record Protocol phase. Q48.Write HTML script to display “Hello world,
If there are any alarms at any point during the session, welcome to the
the alert is attached to world of HTML”, the title as “world of HTML”.
the questionable packet and handled according to the Ans: <HTML><HEAD><TITLE>world of
Alert Protocol. HTML</TITLE><Script language=”Java Script”>
Hello world, welcome to the world of
Q45. Write a JavaScript program to pop up an alert HTML</SCRIPT></HEAD><BODY></BODY>
message. </HTML>
Ans: <HTML> <HEAD> <Script language=”Java
Script”> alert (“This is an alert message for java Q49.Write a JSP program which displays different
script”) message to the user based on the time of day.
</SCRIPT></HEAD><BODY></BODY></HTML> Ans: <%@ taglib prefix=”c”
uri=”http://java.sun.com/jstl/core” %> <html> <body
Q46.Explain in brief how to use hidden controls in a bgcolor=”white”>
web page. Give an example. Further, <jsp:useBean id=”clock” class=”java.util.Date” />
list the advantages and disadvantages of hidden <c:choose><c:when test=”${clock.hours < 12}”>
controls. <h1>Good morning!</h1></c:when><c:when test=”$
Ans: Using HTML hidden control is an easy way to {clock.hours < 18}”><h1>Good day!</h1>
store data in a webpage. </c:when><c:otherwise><h1>Good evening!
The user set the text to store in a hidden control in a </h1></c:otherwise></c:choose>Welcome to our site,
text field. open 24 hours a day.</body></html>.
The code stores the text, the user type in the hidden
control.
Advantages: A hidden control in a Web page is the
easiest way of associating Q50.With diagram explain the life-cycle of Servlet in
some information with the user that’s not directly briefly.
accessible to him. Hidden Ans: The lifecycle of a Servlet consists of the following
controls to store data in the Web page sent to the fundamental stages:
browser and then sent back to the server • Instantiation - The web server creates an
Disadvantages: Storing data in hidden controls is not instance of a servlet. This based on a request or
very secure. The data stored in those a container startup
controls is visible if the user views the page’s HTML • Initialization - The web server creates the
source. We can’t store data between sessions. instance’s init() method. When web server loads
a web application, it also loads the initialization
Q47.Explain the ordered lists and unordered lists. parameters associated with the application.
Ans: Ordered lists: The OL tag displays an ordered, • Service - This is the third state in the servlet
or numbered, list. The default numbering lifecycle. In this state the servlets service()
style is determined by the browser, but you can use the method is called which generates response.
tag’s TYPE attributes to change the i) Setting the content type of the
numbering sequence and numbering style. Use the LI response. The receiving application
tag to designate the individual list items. (browser) uses this information to
Syntax: <OL -START="value"- TYPE= "A" |"a"| "I" know how to treat the response data.
|"I "|"1" -CLASS= "styleClass” –
ii) Print Writer is a class from java.io caption for the table. We can use the CELLSPACING
package that extends the attribute to specify
java.io.writer abstract class. the distance between cells in the table and the
iii) We can use meta tags in the HTML CELLPADDING attribute to
generated to indicate browser not to specify the distance between the border and content of
cache page and some of the similar every cell.
tasks.
• Destroy - This is the final stage in a servlet
lifecycle. In this stage destroy() method is called
before shutting down the servlet.
Q51.What is servlets? Give the Basic servlet
structure.
Ans: Servlets are programs that run on a Web server
and build Web pages.
The outline of a basic servlet that handles GET
requests. GET
requests, are
requests made by
browsers when the
user types in a
URL on the
address line,
follows a link from
a Web page, or
makes an HTML form that does not specify a
METHOD. Servlets can also very easily handle POST
requests, which are generated when someone creates an
HTML form that specifies METHOD=”POST”. A class
should extend HttpServlet and override doGet or
doPost, depending on whether the data is being sent by
GET or by POST. These methods take two arguments:
HttpServletRequest and HttpServletResponse.
HttpServletRequest has methods that find out about
incoming information such as FORM data, HTTP
request headers. HttpServletResponse has methods that
specify the HTTP response line response, PrintWriter
used to headers and most importantly, obtain a send
output back to the client. For simple servlets, most of
the effort is spent in println statements that generate the
desired page. We have to import classes in java.io ,
javax.servlet , and javax.servlet.http. DoGet and doPost
are called by the service method, and sometimes we
want to override service directly.