WTAD Solutions 1

      No Comments on WTAD Solutions 1

WTAD Solutions 1 (1-10)

Jump to WTAD Solution 2

Questions 1 : Explain Following HTML Tag with example: (i) Title, Head (ii) OL, UL (iii) Table with TH,TR,TD

ii) Title :-

The <title> tag is required in all HTML documents and it defines the title of the document.

<Title> tag defines the title in Browser’s toolbar.

It displays the title of web page in search engine..

Example : <title>ABC</title>

Head :-

                It is container for all head element.

It can include a title for the document, scripts, styles, meta information, and more.

The following elements can go inside the <head> element:    <title>,<style>,<base>,<link>,<script> etc.

Example :

<title>Title of the document</title>


ii)OL : The <ol> tag defines an ordered list. An ordered list can be numerical or alphabetical.

<li> tag used to define the item.



UL : The <ul> tag defines an unordered (bulleted) list.



iii) Table with TH,TR,TD : The <th> tag defines a header cell in an HTML table. An HTML table has two kinds of cells 1) Header cells – contains header information (created with the <th> element) and 2) standard cells – contains data (created with the <td> element)

The major difference between <th> elements are bold and centered by default. The texts in <td> elements are regular and left-aligned by default.

The <tr> tag defines a row in an HTML table. A <tr> element contains one or more <th> or <td> elements.

The <td> tag defines a standard cell in an HTML table. The text in <th> elements are bold and centered by default. The text in <td> elements is regular and left-aligned by default.




WTAD Solutions 1 : Question 2. Write a java script to check whether a number entered in textbox is prime or not.

Prime number is the number which is divided by 1 and it self only. Here is the program which shows the number entered in the textbox is prime number of not.
<script type=”text/javascript”>
function pricalc()
var a=from.txt.value;
alert(“Enter the value”);
var num=parseInt(a);
var i;
var n;
alert(“Not a Prime Number”);
alert(“Prime Number”);


} function isInteger(s)
var i;
var c=s.charAt(i);
alert(“Given value is not a number”);
return false;
return true; } </script>


WTAD Solutions 1 : Question 3 : Explain Lifecycle of Servlet with available functions.

A servlet life cycle can be defined as the entire process of Servlet from its creation till the destruction. The following are the paths followed by a servlet

  1. The servlet is initialized by calling the init () method.
  2. The servlet calls service() method to process a client’s request.
  3. The servlet is terminated by calling the destroy() method.
  4. Finally, servlet is garbage collected by the garbage collector of the JVM..


The init() method :

The init method is designed to be called only once. It is called when the servlet is first created, and not called again for each user request. The servlet be loaded when the server is first started..

public void init() throws ServletException {

// Initialization code…


The service() method :

The service() method is the main method to perform the actual task. The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client.

public void service(ServletRequest request,

ServletResponse response)

throws ServletException, IOException{


The doGet() and doPost() are most frequently used methods with in each service request. Here is the signature of these two methods.

The doGet() Method :

A GET request results from a normal request for a URL or from an HTML form that has no METHOD specified and it should be handled by doGet() method.

public void doGet(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

// Servlet code


The doPost() Method:

A POST request results from an HTML form that specifically lists POST as the METHOD and it should be handled by doPost() method.

public void doPost(HttpServletRequest request,

HttpServletResponse response)

throws ServletException, IOException {

// Servlet code


The destroy() method :

The destroy() method is called only once at the end of the life cycle of a servlet.After the destroy() method is called, the servlet object is marked for garbage collection.

public void destroy() {

// Finalization code…



WTAD Solutions 1 : Question 4 : List categories of HTTP Status Code?

These codes fall into five general categories:

  • 100–199

Codes in the 100s are informational, indicating that the client should respond with some other action.

  • 200–299

Values in the 200s signify that the request was successful.

  • 300–399

Values in the 300s are used for files that have moved and usually include a Location header indicating the new address.

  • 400–499

Values in the 400s indicate an error by the client.

  • 500–599

Codes in the 500s signify an error by the server. The constants in  HttpServletResponse that represent the various codes are derived from the standard messages associated with the codes in servlets.


WTAD Solutions 1 : Question 5 : What is Session and Cookie? How they are used in JSP Page? Explain with each one with separate example.


  • The servlet container uses this interface to create a session between an HTTP client and an HTTP server.
  • The session persists for a specified time period, across more than one connection or page request from the user.
  • A session usually corresponds to one user, who may visit a site many times.
  • The server can maintain a session in many ways such as using cookies, Sessions, rewriting URLs.
  • On a typical web site, a visitor might visit several pages and perform several interactions.
  • If you are programming the site, it is very helpful to be able to associate some data with each visitor.  For this purpose, “session”s can be used in JSP.
  • A session is an object associated with a visitor.
  • Data can be put in the session and retrieved from it, much like a Hash table.  A different set of data is kept for each visitor to the site.


<% page language=”java” %>
String name=request.getParameter(“session”);

session.setAttribute(“session “,name);

<title>Name Saved</title>
<p><a href=”showsession.jsp”>Next Page to view the session value</a><p>


  • A webserver can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie.
  • This may not be an effective way because cookie can be modified by client as its stored as plain text, browser may have disable the cookies or not supported.
  • Cookies are text files stored on the client computer and they are kept for various information tracking purpose. JSP transparently supports HTTP cookies using underlying servlet technology.

There are three steps involved in identifying returning users:

  • Server script sends a set of cookies to the browser. For example name, age, or identification number etc.
  • Browser stores this information on local machine for future use.
  • When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user or may be for some other purpose as well.


<TITLE>Setting and Reading Cookies</TITLE>

Cookie[] cookies = request.getCookies();
boolean foundCookie = false;

for(int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
if (c.getName().equals(“color”)) {
out.println(“bgcolor = ” + c.getValue());
foundCookie = true;

if (!foundCookie) {
Cookie c = new Cookie(“color”, “cyan”);
<H1>Setting and Reading Cookies</H1>
This page will set its background color using a cookie.


Question 6 : Write an example to demonstrate the use of various html tags to prepare home page of gtu







<table hihgt=”100%” width=”100” >

<Th>home page</th>

<marquee> welcome to home page</marquee>




Question 7 : Write Down steps for Sending the Cookies from Server to Client

cookies to the client involves three steps (summarized below with details in the following subsections).


  1. Creating a Cookie object: Cookie c = new Cookie(“userID”, “a1234”);
  2. Setting the maximum age: c.setMaxAge(60*60*24*7);
  1. Placing the Cookie into the HTTP response headers:Cookie userCookie = new Cookie(“user”, “uid1234”);

userCookie.setMaxAge(60*60*24*365); // Store cookie for 1 year



Write Down Steps for Receiving Cookies from Client to Server

To send a cookie to the client, you create a Cookie, set its maximum age (usually),then use addCookie to send a Set-Cookie HTTP response header. To read thecookies that come back from the client, you should perform the following two tasks,which are summarized below and then described in more detail in the following subsections.

  1. Call
  2. Loop down the array



String cookieName = “userID”;

Cookie[] cookies = request.getCookies();

if (cookies != null)


for(int i=0; i<cookies.length; i++)


Cookie cookie = cookies[i];

if (cookieName.equals(cookie.getName()))







Question 9 : What is SC? Discuss categories of status code in brief

These codes fall into five general categories:


  • 100–199: Codes in the 100s are informational, indicating that the client should respond with some    other action.
  • 200–299: Values in the 200s signify that the request was successful.
  • 300–399:Values in the 300s are used for files that have moved and usually include a Location  header indicating the new address.
  • 400–499:Values in the 400s indicate an error by the client.
  • 500–599:Codes in the 500s signify an error by the server.

          The constants in HttpServletResponse that represent the various codes

are derived from the standard messages associated with the codes. In servlets, you

usually refer to status codes only by means of these constants.


Question 10 : Write a servlet that just says “Welcome.” To Internet Explorer Users and “Good Bye” to all other non-IE users.

This header identifies the browser or other client making the request and can be used to return different content to different types of browsers.


Public void doGet(HttpServletRequest request,HttpServletResponse response) throws HttpServlet,IOException


PrintWriter out = response.getWriter();

String userAgent = request.getHeader(“User-Agent”);

if ((userAgent != null) &&(userAgent.indexOf(“MSIE”) != -1))


      out.println(“Good Bye”);







Leave a Reply