You are on page 1of 25

Web Technologies

1. Describe the following terminologies in the application development?


a. Front end b. Back end c. Database

The term “front-end” refers to the user interface, while “back-end” means the server
application and database that work behind the scenes to deliver information to the
user.

Front end development


It is also called client-side development. One of the main challenges of front-end is
creating a clear, easy-to-follow user interface. The front-end is built using a
combination of technologies such as Hypertext Markup Language (HTML),
JavaScript and Cascading Style Sheets (CSS).

Back end development


It is also called server side development. One of the main challenges of back-end is
processing client request and generates appropriate response. There are a wide variety
of technologies used to code the application, such as Ruby on Rails, Java,
C++/C/C#, Python and PHP.

Database
Which organizes the information required for application. There are enterprise-level
databases like Oracle, Teradata, Microsoft SQL Server, IBM DB2, EnterpriseDB and
SAP Sybase ASE, as well as other popular databases including MySQL, NoSQL and
PostgreSQL.

1. What are client and server?


Both “client” and “server” refer to computers that are used for different purposes.
Client request to server for resources and services based on the user actions.
Server provides resources and services to one or more clients. Examples of servers
include web servers, mail servers, and file servers.

2. What is the difference between static web page and dynamic web page?
A web application is a collection of the web pages that may contain text, images
audio, video etc.
Static web page
Every user who visits that webpage will receive the exact same information. The
content of the web page is hardcoded or fixed at the time of designing the webpage. It
can't be changed without update the page manually. Usually build with HTML, CSS
and they don't interact with a database.

Dynamic web page


It generates a customized response for every client request. It contains information
that will vary from one user to another. Usually build with JAVA SCRIPT, PHP,
JAVA, PYTHON and database interaction is provided.

3. What is HTML?

HTML stands for HyperText Markup Language. Which is used to create Web pages.

Properties of HTML
 It is free, open standard, not owned by any company or individual.
 It is a tag based language. These tags tell the web browser how to display the
page
 It is a platform independent language that can be used on any platform such as
Windows, Linux, Macintosh, and so on.
 It is not case sensitive language.

4. With an example describe the basic structure of a HTML document.


<HTML>
<HEAD>
<TITLE>welcome page</TITLE>
</HEAD>
<BODY>
Hello World.
</BODY>
</HTML>

Basic tags in HTML


1. HTML Tag: <HTML>
The <HTML> tag encloses all other HTML tags and associated text within the
document.
2. HEAD Tag: <HEAD>
It contains TITLE tag to give the document a title that displays on the browsers title
bar at the top.
3. BODY Tag: <BODY>
The BODY tag contains all the text and graphics of the document with all the HTML
tags that are used for control and formatting of the page.

5. How to create a hyperlink in HTML?


The HTML provides an anchor tag to create a hyperlink that links one page to another
page.
Ex: <a href="second.html">Click for Second Page</a>
The href attribute is used to define the address of the file to be linked. In other words,
it points out the destination page.
6. What is the use of marquee tag?
It scrolls the image or text up, down, left or right automatically.

EX: <marquee>This is an example of html marquee </marquee>

7. Which tag is the use of img tag?


<img> tag is used to add image in a web page.
Ex: <img src="tajmahal.jpg" alt="Taj Mahal"/>
The src attribute is used to define the address of the image to be add in web page.
The alt attribute is used to display the alternate text, in case image was not displayed.

8. Which HTML tag is used to display the data in tabular form?


The HTML table tag is used to display data in tabular form. Here is the list of tags
used while displaying the data in the tabular form:

Tag Description
<table> It defines a table
<tr> It defines a row in a table
<th> It defines a header cell in a table
<td> It defines a cell in a table
<caption> It defines a table caption
<colgroup> It specifies a group of one or more columns in a table for formatting
<col> It is used with <colgroup> element to specify column properties for
each column
<tbody> It is used to group the body content in a table
<thead> It is used to group the header content in a table
<tfooter> It is used to group the footer content in a table

9. What is the use of rowspan and colspan attributes?


ROWSPAN: This property added to table cell which specifies the number of rows the
cell can span (merge). The Default ROWSPAN for any cell is 1.
COLSPAN: This property added to table cell specifies the number of columns the cell
can span (merge). The default COLSPAN for any cell is 1.
Example:

<table width="90%" border="1" >


<tr>
<th colspan=2" >Header (spans 2 columns)</th>
</tr>
<tr>
<td rowspan="2">data (spans 2 rows)</td>
<td>data</td>
</tr>
<tr>
<td>data</td>
</tr>
</table>

10. What is a frame?


The browser screen divides into a number of parts, which might be completely
independent. Each part of the screen is called frame and each rectangle can hold a
different document.
Frames documents are generated by:
 FRAMESET Tag
 FRAME Tag
<FRAMESET> Tag:
Frameset tag defines the number of columns and rows in a frameset.
Example: <FRAMESET rows="20%, 70%, 10%">
The screen divide into three rows 20% row is on top, 70% row is in the middle, and
10% row is on the bottom.
<FRAMESET cols="20%, 80 %">
The screen divides into two columns one 20% on left and other 80% on right.

<FRAME> Tag:
The <FRAME> tag enables to specify just what appears in row or column.
Example: <FRAME SRC="contents.html">
SRC (Source): Specifies the Web page that you want to display in the frame.

11. What is a HTML form?


An HTML form is a set of elements used to ritrieve informations from the user.
Once filled, the form can be submitted to a processing program, that runs on the
server.
The <FORM> tag may have an attribute “METHOD” that can take the values GET or
POST. The difference between the two resides in how the form data are going to be
sent to the server indicated in the “ACTION” attribute.

DESCRIPTION:
<FORM NAME = “name” ACTION="URL" METHOD="Action">
ACTION : Provides the URL address where the request with the form content will be
sent. If the field ACTION is absent, the request will be sent to the current server.
METHOD : HTTP command used to communicate with the HTTP server. There are
two methods, GET and POST.

12. What are the components of form tag?


Form Components:-
< INPUT > Tag:This is an empty tag, no end tag. It is used to add graphical user
components such as text fields, password fields, check boxes, radio buttons, reset
buttons and submit buttons in the form.
< input type = “text” | “password” | “checkbox” | “radio” | “submit”
name=”string” value=”string” size=”n”>
In the above tag, the attribute type is used to implement text, password, checkbox,
radio and submit button.
Attributes of < INPUT >
NAME: It defines name for the form components. This field is required for all the
types of input except submit and clear.
SIZE: Specifies the size of the input field in number of characters, used with text or
password field.
MAXLENGTH: Specifies maximum number of characters that can be entered into a
text or password field.
VALUE: For a text or password field, it defines the default text displayed. For a
check boxes or radio button, it specified the value that is returned to the server if the
box or button is selected. For submit and reset buttons, it defines the label of the
button.
CHECKED: Sets a checkbox or radio button to ‘on’.
TYPE: Set the type of input field.

It can take following values:


TEXT: used for single line text field.
PASSWORD: Same as TEXT, but entered text appear as "*" characters
TEXT AREA -: It is used for multiple lines text field
RADIO: It is used for attributes that accepts a single value from a set of alternatives.
(If the name of the radio buttons are equal it act as a group)
SUBMIT: This creates a button that submits the form. Performance is base On
submit,etc..events specified with the ACTION attribute of the <FORM> Tag.
RESET - This creates a button, when selected, resets the value of all the fields in the
form to their initial values
HIDDEN: This creates an invisible field, but the content of the field are sent with the
submitted form.
The <SELECT> Tag: This is a container tag, allows user to select one of the sets of
alternatives described by textual labels. Every alternatives is represented by
<OPTION>, an empty tag.
Attributes of <SELECT>:
MULTIPLE: Allows selecting more than item from the list.
NAME: Specifies the name that will be submitted as a name-value pair.
SIZE: Specifies the number of usable items. By default size=1 the SELECT element
treated as pull down menu. For size more than one, SELECT element treated as a list.
The <OPTION> Tag: An Empty tag <OPTION> can only be used within
<SELECT>. Each item in <SELECT> is represented by <OPTION>. Attributes of
<OPTION>: SELECTED: This attribute indicates that option is initially selected.
VALUES: This attribute indicates the value of the option selected.
Example:

<html>
<head> <title> Use of Form </title> </head>
<body>
<form action=" " method="post" name="form1">
<p>Please fill out the following information</p>
NAME : <input type="text" name="textfield1"> <br>
City: <select name="select" size=5>
<option>New Delhi</option>
<option selected>Bombay</option>
<option>Culcutta</option>
<option>Madras</option>
<option>Banglore</option>
<option>Hyderabad</option>
</select> <br>
State: <select name="select">
<option>AP</option>
<option>MP</option>
<option>Karnatak</option>

<option>Tamilnadu</option>

<option selected>Maharashtra</option>
</select> <br>
Address: <textarea name="textarea"></textarea> <br>
Mail ID: <input type="text" name="textfield4"><br>
<H4>Which feed back u want to enter <h4><br>
<input type="checkbox" name="checkbox" value="checkbox"> Internet<br>
<input type="checkbox" name="checkbox" value="checkbox">Designing
HTML<br>
<input type="checkbox" name="checkbox" value="checkbox"> web site<br>
<input type="checkbox" name="checkbox" value="checkbox">Development
Tools<br>
<h4> give feedback <h4>
<input name="radiobutton" type="radio" value="radiobutton">Excellent
<input name="radiobutton" type="radio" value="radiobutton">Good
<input name="radiobutton" type="radio" value="radiobutton"> Satisfactory
<br>
<input type="reset" name="Reset" value="Reset">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

13. What the difference is between get and post method?

Get method Post method


The request parameters are transmitted as The request parameters are passed with
a query string appended to the request. the body of the request
This causes security risk. In address bar It is more secure
we can see the passwords also
It is limited to transmit 1024 characters It is not restricted to sending only textual
data only data. It can send stream data also.
It is not appropriate to transmit large It can send much more information to the
amount of data like files, images, server.
videos..etc.

14. What is the difference between div and span tags?


The difference between span and div is that a span element is in-line, while a div
element is block-line often used to group larger chunks of code.

15. What is the use of CSS?


CSS stands for Cascading Style Sheets. CSS describes how HTML elements are to be
displayed on screen not what is being displayed.

16. What are the ways to include CSS in HTML?


CSS can be added to HTML elements in 3 ways

Inline - by using the style attribute in HTML elements.


Internal - by using a <style> element in the <head> section.
External - by using an external CSS file.

Inline Styles:
An inline style may be used to apply a unique style for a single eelement.
To use inline styles, add the style attribute to the relevant element. The style attribute can
contain any CSS property.
The example below shows how to change the color and the left margin of a <h1> element:
Program:
<html>
<body>
<h1 style="color:blue;margin-left:30px;">This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:

Internal Styles Sheet:


An internal style sheet may be used if one single page has a unique style.
Internal styles are defined within the <style> element, inside the <head> section of an HTML
page:
Program:
<html>
<head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;margin-left: 40px;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
Output:

External Styles Sheet:


With an external style sheet, you can change the look of an entire website by changing just
one file!
Each page must include a reference to the external style sheet file inside the <link> element.
The <link> element goes inside the <head> section:
Program:
Mystyle.css
<html>
body {
<head>
background-color: linen;
<link rel="stylesheet" type="text/css" href="mystyle.css">
}
</head>
h1 {
<body>
color: maroon;margin-left: 40px;
<h1>This is a heading</h1>
}
<p>This is a paragraph.</p>
</body>
</html>
Output:

17. What are the different selectors used to apply CSS styles?
CSS selectors are used to "find" (or select) HTML elements based on their element
name, id, class, attribute, and more.
1. Element Type Selector:
The element selector selects elements based on the element name.
You can select all <p> elements on a page like this :
Example:
<html>
<head>
<style>
p{
color: red;
background-color: linen;
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

ID Selector
It uses the id attribute of an HTML element to select a specific element. The id of an
element should be unique within a page, so the id selector is used to select one unique
element. To select an element with a specific id, write a hash (#) character, followed
by the id of the element.
Example:
<html>
<head>
<style>
#abc {
color: red;
background-color: linen;

</style>
</head>
<body>
<h1>This is a heading</h1>
<p id="abc">This is a paragraph.</p>
</body>
</html>
3. Universal Selector
Rather than selecting elements of a specific type, the universal selector quite simply
matches the name of any element type, It selects all elements on a page.
Example:
<html>
<HEAD>
<style>
*{
color: green;
background-color: linen;
}
</style>
</HEAD>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>

4. Class Selector
The class selector selects elements with a specific class attribute. To select elements
with a specific class, write a period (.) character, followed by the name of the class.
Example:
<html>
<HEAD>
<style>
.abc {
color: green;
font-size: 20px;
background-color: linen;
}
</style>
</HEAD>
<body>
<h1 class="abc">This is a heading</h1>
<p>This is a paragraph.</p>
<h2 class="abc">This is a heading</h1>
</body>
</html>
18. What is the use of JavaScript?
JavaScript is a client-side, event-based, object oriented scripting language used to add
dynamic interactivity to web pages.
The main purpose of JavaScript is to perform basic client side validations like check
emptiness of the form field, mobile number (10 digits), E-Mail verification (proper
email structure). We can do same validations at server side also, but it is extra burden
to the server and creates network traffic.
We cannot perform data base validations in java script, It is possible to do at server
side only.

19. What are the ways to add Java Script to HTML?

1. In the <head> section: These scripts will be called when an event triggers them.
Example:
<html>
<head>
<script type="text/javascript">
function sayHello()
{
alert("Hello World")
}
</script>
</head>
<body>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>

2. In the <body> section: These scripts will run as the page loads.
Example:
<html>
<head>
</head>
<body>
<script type="text/javascript">
document.write("Hello World")
</script>
<p>This is web page body </p>
</body>
</html>

3. In an external file: write JavaScript in external documents that have the file
extension .js. Each page must include a reference to the external .js file inside the
<script> element.
Example: message.js
<html> function msg()
<head> {
<script type="text/javascript" src="message.js"> alert("Hello World");
</script> }
</head>
<body>
<p>Welcome to JavaScript</p>
<form>
<input type="button" value="click" onclick="msg()"/>
</form>
</body>
</html>
20. What are the popup boxes can be generate in JavaScript?
In JavaScript we can create three kinds of popup boxes:
1. Alert Box: It is often used if you want to make sure information comes through to
the user. When an alert box pops up, the user will have to click "OK" to proceed.
Syntax: alert("sometext")

2. Confirm Box: A confirm box is often used if you want the user to verify or accept
something. When a confirm box pops up, the user will have to click either "OK"
or "Cancel" to proceed. If the user clicks "OK", the box returns true. If the user
clicks "Cancel", the box returns false.
Syntax: confirm("sometext")

3. Prompt Box: A prompt box is often used if you want the user to input a value
before entering a page. When a prompt box pops up, the user will have to click
either "OK" or "Cancel" to proceed after entering an input value. If the user clicks
"OK" the box returns the input value. If the user clicks "Cancel" the box returns
null.
Syntax: prompt("sometext","defaultvalue“)

21. What are the packages need to import to connect with Database from java
application?
In order to connect with database from java we need to import the following
packages.
java.sql.*; (usually enough)
javax.sql.*; (for advanced features, such as scrollable result sets)

22. What is a JDBC driver?


It is a software which converts java calls to database calls and database calls to java
calls. Each database provides drivers to interact with different technologies. One
driver to interact with java and another driver to interact with .net like that.

23. What are the different kinds of JDBC drivers available?

There are 4 types of JDBC drivers:

1. JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The
JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function
calls. We no need to install separately, It is by default available with JDK up to
java7.0 Oracle does not support the JDBC-ODBC Bridge from Java 8.
Advantages:
 It is very easy to use
 Data base independent driver

Disadvantages:

 It is slowest driver
 It is only applicable for windows machines

2. Native-API driver (partially java driver)


The Native API driver uses the client-side libraries of the database. The driver
converts JDBC method calls into native calls of the database API. It is not
written entirely in java.

Advantages:
 It is relatively fast than type-1 driver
 portable

Disadvantages:

 Database dependent driver


 All databases vendors may not provide native library.

3. Network Protocol driver (fully java driver)


The Network Protocol driver uses middleware (application server) that
converts JDBC calls directly or indirectly into the vendor-specific database
protocol. It is fully written in java.

Advantages:
 No client side library is required because of application server that can
perform many tasks like auditing, load balancing, logging etc.

Disadvantages:

 Network support is required on client machine.


 Requires database-specific coding to be done in the middle tier.
 Maintenance of Network Protocol driver becomes costly because it
requires database-specific coding to be done in the middle tier.

4. Thin driver (fully java driver)

The thin driver converts JDBC calls directly into the vendor-specific database
protocol. That is why it is known as thin driver. It is fully written in Java
language.

Advantages:
 Performance is high.
 Platform independent
Disadvantages:

 Data base dependent driver

24. What are steps to connect java application with database?


1. Loading the JDBC driver
The JDBC driver must be available before the Java application can connect to the
DBMS. The driver is loaded by calling the Class.forName() method and by
passing the name of the driver. Here forName() is a static method of class Class.
Example: Class.forName("com.mysql.jdbc.Driver");

2. Creating a Connection to Data Base


Once the driver is loaded, getConnection() method of DriverManager Class is
used to create a connection with the database.
Syntax:
getConnection(String url, String username, String password)

where url - location of database


username – data base username
password – database password
Example:
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost/databasename","root","roo
t");

3. Creating a statement object


The statement object is responsible to execute queries with the database.
createStatement() method of Connection object is used create a Statement
object.
Example:
Statement stmt=con.createStatement();

4. Executing SQL statements


The methods of Statement object is used to execute a query and return a ResultSet
object that contains the response from the DBMS.
Methods of statement object:
executeQuery() is used for SELECT statement.
executeUpdate() is used for create, alter or drop table.
execute() is used when multiple results may be returned

Example:
String query="create table employee1(empid varchar(20),empname
varchar(30),empsal varchar(20))";
stmt.executeUpdate(query);

5. Closing the connection


The close()method of Connection interface is used to close the connection.
Con.close()

25. What are the JDBC different interfaces available in java.sql.* package?

The java.sql package contains following interfaces for JDBC API.

o Connection: The Connection object is created by using getConnection() method of


DriverManager class. DriverManager is the factory for connection.
o Statement: The Statement object is created by using createStatement() method of
Connection class. The Connection interface is the factory for Statement.
o PreparedStatement: The PrepareStatement object is created by using
prepareStatement() method of Connection class. It is used to execute the
parameterized query.
o ResultSet: The object of ResultSet maintains a cursor pointing to a row of a table.
Initially, cursor points before the first row. The executeQuery() method of Statement
interface returns the ResultSet object.
o ResultSetMetaData: The object of ResultSetMetaData interface cotains the
information about the data (table) such as numer of columns, column name, column
type, etc. The getMetaData() method of ResultSet returns the object of
ResultSetMetaData.
o DatabaseMetaData: DatabaseMetaData interface provides methods to get metadata
of a database such as the database product name, database product version, driver
name, name of the total number of tables, the name of the total number of views, etc.
The getMetaData() method of Connection interface returns the object of
DatabaseMetaData.
o CallableStatement: CallableStatement interface is used to call the stored procedures
and functions. We can have business logic on the database through the use of stored
procedures and functions that will make the performance better because these are
precompiled. The prepareCall() method of Connection interface returns the instance
of CallableStatement.

26. What are the different JDBC statements?


There is three types of JDBC statements given in the following table.

Statement: Statement is the factory for resultset. It is used for general purpose access
to the database. It executes a static SQL query at runtime.

PreparedStatement: The PreparedStatement is used when we need to provide input


parameters to the query at runtime.

CallableStatement: CallableStatement is used when we need to access the database


stored procedures. It can also accept runtime parameters.
27. What is servelt?
Java Servlets are server-side Java programs that process and answer client requests.

28. What is the difference between servlets and applets?


Servlets executes on Servers. Applets executes on browser. Unlike applets, servlets
have no graphical user interface.

29. What are the ways to implement servelet?

The servlet can be implemented in three ways:

1. By implementing Servlet interface,


2. By inheriting GenericServlet class, (or)
3. By inheriting HttpServlet class

30. What are difference in implementing Servlet by Servelt interface, GenericServlet


abstract class and HTTP servelt abstract class?

Servlet interface: This interface contains the following five methods.

1. public abstract void init(ServletConfig)


2. public abstract void service(ServletRequest, ServletResponse)
3. public abstract void destroy()
4. public ServletConfig getServletConfig()
5. public String getServletInfor()

If we implement servlet by implementing Servlet interface, we


have to provide body for all the above 5 methods.

GenericServlet abstract class: If we implement Servlet by extending GenericServlet class,


then we have to provide body for only service(- -) method. Default implementation for
remaining methods was provided by GenericServlet.

HTTPServlet: If we implement servlet by extending HTTPServlet class, they we have to


provide body for doGET(- -) or doPOST(- -) only.

31. What are the servlet life cycle methods or methods in Servlet interface?
Servlet life cycle consists of a series of events that begins when the Servlet container
loads Servlet, and ends when the container is closed down Servlet.

The following are the life cycle methods of a servlet instance:


init()
This method is called once for a servlet instance. When first time servlet is called, servlet
container creates instance of that servlet and loaded into the memory. Future requests will be
served by the same instance without creating the new instance. Servlet by default
multithreaded application. init() method is used for inilializing servlet variables which are
required to be passed from the deployment descriptor web.xml. ServletConfig is passed as the
parameter to init() method which stores all the values configured in the web.xml. It is more
convenient way to initialize the servlet.

service()
This method is called for the each request. This is the entry point for the every servlet request
and here we have to write our businesslogic or any other processes. This method
takes HttpServletRequest and HttpServletresponse as the parameters. It is not mandatory to
write this method, normally developers are interested in writing doGet() or doPost() methods
which is by default called from the service() method. If you override service(), it is your
reponsibility to call the appropriate methods. If you are not overridden the service() method,
based on the types of the request the methods will be called.

destroy()

This method will be called once for a instance. It is used for releasing any resources used by
the servlet instance. Most of the times it could be database connections, Fill IO operations,
etc. destroy() is called by the container when it is removing the instance from the servlet
container.Servlet instance is deleted or garbage collected by the container only when the web
server issues shut down or the instance is not used for a long time.

32. What is the use of deployment descriptor (web.xml)?


In a java web application a file named web.xml is known as deployment descriptor.
When a request comes web server uses web.xml file to map the URL of the request to
the specific code that handle the request.
Example:

<web-app>
<servlet>
<servlet-name>servletName</servlet-name>
<servlet-class>servletClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>servletName</servlet-name>
<url-pattern>./request</url-pattern>
</servlet-mapping>
</web-app>

When a request comes it is matched with url pattern in servlet mapping attribute.
When url matched with url pattern web server try to find the servlet name in servlet
attributes same as in servlet mapping attribute. When match found control is goes to
the associated servlet class.

33. What is the difference between RequestDispatcher and sendRedirect?

RequestDispatcher: This interface provides the option of dispatching the client’s request to
another web resource, which could be an HTML page, another servlet, JSP etc. It provides
the following two methods:
1. public void forward(ServletRequest request, ServletResponse response) : When this
method is called, the control is transferred to the next resource called.

Example:
RequestDispatcher rd = request.getRequestDispatcher("servlet2");
rd.forward(request, response);

2. public void include(ServletRequest request, ServletResponse response) : When this


method is called, the control still remains with the calling resource. It simply includes the
processed output of the calling resource into the called one.

Example:
RequestDispatcher rd = request.getRequestDispatcher("servlet2");
rd.forward(request, response);

sendRedirect method: The HttpServletResponse interface contains a method public void


sendRedirect(String URL)

This method is used redirect response to another resource, which may be a servlet, jsp or an
html file.

Example: response.sendRedirect("https://www.google.co.in/#q=" + name);


The main difference between these two techniques is we can use request dispatcher to
establish the communication between the resources only inside the application, where
as sendRedirect can be used to establish communication between resources of two
different applications.

34. What is the difference between ServeletConfig and ServletContext objects?


ServletConfig:
1. For every servlet web container creates one ServletConfig object
2. Within the servlet we can get its config object as follws
ServletConfig config = getServletConfig( );
3. By using config object, Servlet can get its configuration information like
logical name of the servlet, initialization parameters… etc.
getServletName()
getInitParameter()

ServletContext

1. For every web application, web container creates one ServletContext object to
hold application level configuration information.
2. Within the servlet we can get context object as follows
ServletContext context=config.getServletContext();
3. On the ServletContext object we can call the following methods.
getRequestDispatcher()
getInitParameter()
getServerInfo()
getResourcepaths()

35. What is a session?


Particular interval of time from login to logout of user is known as session.
36. What are the different session tracking mechanisms?

1) cookies

A cookie is a small piece of information that is persisted between the multiple client requests.
In cookies technique, we add cookie with response from the servlet. So cookie is stored in the
cache of the browser. After that if request is sent by the user, cookie is added with request by
default. Thus, we recognize the user as the old user.

Example:
Cookie ck=new Cookie("user","amaranath");//creating cookie object
response.addCookie(ck);//adding cookie in the response

Advantages
1. Simplest technique of maintaining the state.
2. Cookies are maintained at client side.

Disadvantages
1. It will not work if cookie is disabled from the browser.
2. Only textual information can be set in Cookie object.

2) hidden fields

In case of Hidden Form Field a hidden (invisible) textfield is used for maintaining the state of
an user.

Example: <input type="hidden" name="uname" value="amaranath">\

Advantages
1. It will always work whether cookie is disabled or not.

Disadvantages
1. It is maintained at server side.
2. Extra form submission is required on each pages.
3. Only textual information can be used.

3) URL rewriting

In URL rewriting, we append a token or identifier to the URL of the next Servlet or the next
resource. We can send parameter name/value pairs using the following format:

Example: url?name1=value1&name2=value2&??

Advantages
1. It will always work whether cookie is disabled or not (browser independent).
2. Extra form submission is not required on each pages.

Disadvantages
1. It will work only with links.
2. It can send Only textual information.

4) HttpSession

In this case, container creates a session id for each user.The container uses this id to identify
the particular user.An object of HttpSession can be used to perform two tasks:

1. bind objects
2. view and manipulate information about a session, such as the session identifier,
creation time, and last accessed time.

The HttpServletRequest interface provides two methods to get the object of HttpSession:

1. public HttpSession getSession():Returns the current session associated with this


request, or if the request does not have a session, creates one.
2. public HttpSession getSession(boolean create):Returns the current HttpSession
associated with this request or, if there is no current session and create is true, returns
a new session.

37. What is JSP?


JSP stands for Java Server Pages. JSP technology is used to create web application just like Servlet
technology.

advantages of JSP over Servlet


1) Extension to Servlet

JSP technology is the extension to Servlet technology. We can use all the features of the
Servlet in JSP. In addition to, we can use implicit objects, predefined tags, expression
language and Custom tags in JSP, that makes JSP development easy.

2) Easy to maintain

JSP can be easily managed because we can easily separate our business logic with
presentation logic. In Servlet technology, we mix our business logic with the presentation
logic.

3) Fast Development: No need to recompile and redeploy

If JSP page is modified, we don't need to recompile and redeploy the project. The Servlet
code needs to be updated and recompiled if we have to change the look and feel of the
application.

4) Less code than Servlet

In JSP, we can use many tags such as action tags, JSTL, custom tags, etc. that reduces the
code. Moreover, we can use EL, implicit objects, etc.

38. What are the JSP elements?

The scripting elements provides the ability to insert java code inside the jsp. There are three
types of scripting elements:
1. scriptlet tag: A scriptlet tag is used to execute java source code in JSP.

Example:
<html>
<body>
<% out.print("welcome to jsp"); %>
</body>
</html>

2. expression tag

The code placed within JSP expression tag is written to the output stream of the
response. So you need not write out.print() to write data. It is mainly used to print the
values of variable or method.

Example:

<html>
<body>
<%= "welcome to jsp" %>
</body>
</html>

3. declaration tag

The JSP declaration tag is used to declare fields and methods. the code written inside
the jsp declaration tag is placed outside the service() method of auto generated servlet.

Example:

<html>
<body>
<%! int data=50; %>
<%= "Value of the variable is:"+data %>
</body>
</html>

39. What are JSP implicit objects?


40.
41. What is jar file?
jar stands for java archive file. it contains a group of .class files

42. What is war file?


war stand for web archive file. A war file represents one web applications which
contains servlets, japs, HTML, Javascript.. etc related to the application. The main
advantage of maintainin web application in the form of war file is project deployment,
delivery and transportation is easy.
43. What is the difference between web server and application server?

To run web applications, Web server requires. Web server provides support for Servlets, JSP, HTML...
To run Enterprise applications, application server required. Application server provides support for
Servlet, JSP, EJB, JMS… web server is a part of application server.

Examples for web servers: Apache Tomcat, Jetty

Examples for application servers: JBOSS, Glashfish, Weblogic, Websphere

You might also like