313 41 - Web Technology - Part 1 5 Marks XML (Extensible Markup Language)
313 41 - Web Technology - Part 1 5 Marks XML (Extensible Markup Language)
5 Marks
1
Lightweight: It should be possible to implement a component as small as a push button or as
large as a complete spreadsheet or word processor.
Simple to create: it should be a simple job to create a java component with our
implementing countless methods.
Hostable in other component models : It should be possible to use JavaBeans as a first-class
ActiveX, OpenDoc, or other component
Able to access remote data: A Java component may use any of the standard distributed
objects (Remote Method Invocation RMI) or distributed data mechanisms to access remote
data
3. Design a HTML form for railway reservation system using suitable background design and
text color
<html>
<head>
</head>
<body>
onsubmit="return(validate());">
align="center"cellpadding="2">
<tr>
<td colspan="2"
</td>
</tr>
<tr>
<td>From</td>
size="30"></td>
</tr>
2
<tr>
<td>To</td>
</tr>
<tr>
<td>Train No/Name</td>
id="trainno"size="30"></td>
</tr>
<tr>
<td>class</td>
<td><select name="class">
<option value="-1"selected>select</option>
<option value="3A">3A</option>
<option value="2A">2A</option>
</select></td>
</tr>
<tr>
<td>NO.of seats</td>
<option value="-1"selected>select</option>
<option value="1">1</option>
<option value="2">2</option>
<select></td>
</tr>
<tr><td>passenger</td>
<tr><td>age</td></tr>
3
<tr><td>Gender</td></tr>
</tr>
<td><input type="text"name="p1"size="30"></td>
<td><input type="text"name="age"size="2"></td>
<td><select name="Gender"
</td></tr>
<tr>
<td><select name="Gender">
</td></tr>
<tr>
<td>Address</td>
size="50"></td>
</tr>
<tr>
<td>Payment Mode</td>
</tr>
4
<tr>
<td>Mobile no.</td>
size="30"></td>
</tr>
<tr>
</td>
</tr>
</table>
</form>
</body>
</html>
5
o A web server is also known as an HTTP Server.
o It responds to request from a web browser by returning Html images, applets or other
data.
o It is also responsible for enforcing security policies, storing frequently requested files in
cache memory logging request and much more.
Example web server is Tomcat web server.
o Exploring The Tomcat Directory Structure
bin/
The *.sh files (for Unix and Mac OS systems) are functional duplicates of the *.bat files (for
Windows systems).
conf/
You will modify server.xml and tomcat-users.xml to adjust logging, authentication and access
control, enable TLS/SSL, etc.
Web applications can override some server-wide settings in their own configuration file (e.g.,
the web deployment descriptor).
webapps/
You will also be using the manager application that comes with the Tomcat Servlet Container
during this tutorial.
logs/
This is one of the directories you will be looking for log files (the TDS logs elsewhere by default).
The log files should be your first stop for troubleshooting Tomcat and TDS issues. (Hint, hint).
Logs files may contain useful information for assessing the security of your system.
6
Servlet interface needs to be implemented for creating any servlet (either directly or indirectly).
It provides 3 life cycle methods that are used to initialize the servlet, to service the requests, and
to destroy the servlet and 2 non-life cycle methods.
There are 5 methods in Servlet interface. The init, service and destroy are the life cycle methods
of servlet. These are invoked by the web container.
Client-side script
step2: Client-side script run in the browser and process request without call-backs to the server.
step3: when a call to the database required JavaScript and ajax requests to the back end.
step4: The back-end server-side scripts process the request. pull what they read from the database then
send it back.
step5: Server-side scripts process the data, then update the site.
7
7. Write a java script that scrolls a text message in the status bar of the browser window?
<html>
<head>
<title>Scrolling Text</title>
<script language="JavaScript">
var scrollPos = 0
window.setInterval("displayText('"+text+"')", milliseconds)
function displayText(text) {
++scrollPos
8
if(scrollPos > maxScroll) {
scrollPos = 0
blanks = ""
</script>
</head>
</body>
</html>
JSP pages allow you to separate front-end presentation from business logic (middle and back-
end tiers).
It is a great Rapid Application Development (RAD) approach to Web applications.
When working with JSP pages, you just need a regular text editor such as Notepad on Windows
or Emacs on Unix
9
Installing JSP
Setting up the Java Development Kit
Step1: It involves downloading an implementation of the Java Software Development Kit (SDK) and
fixing the environment variable. You can download SDK from Oracle’s Java site by visiting the below URL:
https://www.oracle.com/java/technologies/javase-downloads.html
Step2: You download your Java implementation, follow the given instructions to put in, and configure
the setup. Finally set the JAVA_HOME environment variables to ask the directory that contains java and
javac, typically java_install_dir/bin and java_install_dir respectively.
set PATH = C:\jdk1.8.0_181\bin;%PATH%
set JAVA_HOME = C:\jdk1.8.0_181
10
Client-side scripting refers to a procedure where the code with an HTML web page is sent to
the client via the server.
In this case, the code is linked to the Script. In simpler terms, client-side scripting refers to
an approach where scripts are executed by browsers without connecting to the server.
The code runs in the browser of the client's computer, either when the web page is loading
or when the page has loaded.
Client-side scripting is mostly utilized to create dynamic user interface elements like pull-
down menus and animation buttons, navigation tools, data validation, and more.
Nowadays, it is increasing and evolving every day. This means that writing web
programming for clients is now much easier and quicker and, in turn, reduces the load on
servers.
JavaScript, as well as jQuery, are the most significant web scripting languages that are
widely used to create responsive and dynamic web pages.
A browser (temporarily) is able to download the Script locally on the computer and begins
processing it in the absence of the server. Thus, the scripting on the client is dependent on
the browser.
11
11. Differentiate static web pages and dynamic web pages.
Basics The content on web pages remains the This type of web page is behavioral. The
same unless someone physically makes content of pages is capable of differing for
any changes on its hard disk (manual different visitors. It keeps changing with
alterations). time and other parameters.
Definition A static web page is a simple HTML written A dynamic web page is a type of page
page that serves as a type of direct written in complex languages like AJAX,
response from a browser to the server. All ASP.NET, etc. The data here gets rendered
the data and info remains static in nature, to some capacity and interpretation for
and it stays the same unless someone producing varied content for different users
manually makes any changes to it. visiting the page at different times.
Complexity These types of web pages are very simple. These types of web pages are complicated.
The data in these pages remain static and They go through the process of
require no interpretation before the interpretation- making the data dynamic in
process of rendering. Thus, it comes with nature. Due to this, such pages become way
no complexity. more complex as compared to any static
web pages.
Frequency of Content and information rarely change on The content and information change
Information a static web page. frequently on a dynamic web page.
Change
Loading Time These web pages take a very short time to These web pages take longer to load as
load as compared to the dynamic ones. It compared to the static ones. It is because of
is because they contain very static data the more complex, dynamic data present in
and info on the pages. these web pages.
Use of Database The static web pages generally do not use The dynamic web pages use databases
12
databases. They do not require data because it involves frequent data and info
redecoration very often. redecoration.
Languages Used Languages like CSS, JavaScript, HTML, etc., Languages like ASP.NET, ASP, AJAX, CGI,
come into play when writing static web etc., come into play when writing dynamic
pages. It uses only simple languages. web pages. It requires some very complex
languages for a stable operation.
Application These do not contain any application These contain application programs for
Program programs. various services.
Work Required Less work and complexity go into designing More work and complexity go into
static web pages. designing dynamic web pages.
Cost of Designing static web pages requires very Designing dynamic web pages is more costly
Development low cost as compared to dynamic ones. as compared to static ones.
Rendered Data The data in static web pages don’t change The data and info in dynamic web pages
automatically. One needs to manually first stay interoperate at the server-side.
make necessary changes on it- making it Due to this, the data doesn’t remain similar
static in nature. on each call- making the data contained in it
dynamic in nature.
13
Scripting languages are a type of programming language that is used to write scripts.
A script is a series of instructions that tells a computer how to perform a specific
task.
Scripts are typically used to automate tasks or to add functionality to an application.
JavaScript is a scripting language that is used to add interactivity to webpages. It is
commonly used in conjunction with HTML and CSS to create dynamic and
responsive web applications
14
In ADO.NET the type of the Connection is depended on what Database system you are working
with. The following are the commonly used connections in the ADO.NET
SqlConnection
OleDbConnection
OdbcConnection
Command
The Command object is used to perform an action on the data source. Command object can execute
stored procedures and T-SQL commands.
You can execute SQL queries to return data in a DataSet or a DataReader object. Command object
performs the standard Select, Insert, Delete, and Update T-SQL operations.
DataReader
The data returned by a DataReader is always read-only
The DataReader is built as a way to retrieve and examine the rows returned in response to your query as
quickly as possible
DataAdapter
The DataAdapter takes the results of a database query from a Command object and pushes them into a
DataSet using the DataAdapter.Fill() method. Additionally the DataAdapter.Update() method will
negotiate any changes to a DataSet back to the original data source
Command Builder
The work of Command Builder is to generate Command as per changes in DataRows.
Transaction
The Transaction object is used to execute the backend transaction. Transactions are used to ensure that
multiple changes to database rows occur as a single unit of work
Parameters
Parameter object is used to solve the SQL Injection attack problem while dealing with the user input
parameters.
Disconnected Model
Data Set
The DataSet Object is the parent object to most of the other objects in the System.Data
namespace
Its primary role is to store a collection of DataTables and the relations and constraints between
those DataTables.
DataSet also contains several methods for reading and writing XML, as well as merging other
DataSets, DataTables and DataRows.
15
DataTable
DataTable stores a table of information, typically retrieved from a data source. DataTable allows
you to examine the actual rows of a DataSet through rows and columns collections.
Once the DataTable is filled the database connection is released and operates disconnected
only.
DataRows
The DataRow class permits you to reference a specific row of data in a DataTable. This is the
class that permits you to edit, accept, or reject changes to the individual DataColumns of the
row
DataColumns
DataColumns is the building block of the DataTable. A number of such objects make up a table.
Each DataColumn object has a DataType property that determines the kind of data that the
column is holding. data table
Syntax
Here, column1, column2, ... are the field names of the table you want to select data from.
The table_name represents the name of the table you want to select data from.
UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
16
Note: Be careful when updating records in a table! Notice the WHERE clause in the UPDATE statement.
The WHERE clause specifies which record(s) that should be updated. If you omit the WHERE clause, all
records in the table will be updated!
DELETE Syntax
Note: Be careful when deleting records in a table! Notice the WHERE clause in the DELETE statement.
The WHERE clause specifies which record(s) should be deleted. If you omit the WHERE clause, all records
in the table will be deleted!
2. If you are adding values for all the columns of the table, you do not need to specify the column names
in the SQL query. However, make sure the order of the values is in the same order as the columns in the
table. Here, the INSERT INTO syntax would be as follows:
17
o In this program we are making the using of html form.
o When the values are entered in the html form then these values are checked by the
controller, then on checking the values the output will be displayed to the user.
o The code of the program is given below:
<html>
<head>
<title>Conditional Test</title>
</head>
<body>
<form method = "get" action = "Conditional.jsp">
Enter the number<input type = "text" name = "number" value = "">
<input type = "submit" name = "submit" value = "submit">
</form>
</body>
</html>
<% switch (Integer.parseInt(request.getParameter("number")))
{
case 0: %>
You have entered the number 0
<% break;
case 1: %>
You have entered the number 1
<% break;
default: %>
You can enter either o or 1
<%
}
%>
Output
18
16. How does a web server and browser communicate with each other?
Web Server - A web server is also known as an HTTP Server. It responds to request from a web
browser by returning Html images, applets or other data.
Web browsers communicate with web servers using the HyperText Transfer Protocol (HTTP).
When you click a link on a web page, submit a form, or run a search, the browser sends an HTTP
Request to the server. This request includes:
A URL identifying the target server and resource (e.g. an HTML file, a particular data point on the
server, or a tool to run).
A method that defines the required action (for example, to get a file or to save or update some
data). The different methods/verbs and their associated actions are listed below:
o GET: Get a specific resource (e.g. an HTML file containing information about a product,
or a list of products).
o POST: Create a new resource (e.g. add a new article to a wiki, add a new contact to a
database).
o HEAD: Get the metadata information about a specific resource without getting the body
like GET would. You might for example use a HEAD request to find out the last time a
resource was updated, and then only use the (more "expensive") GET request to
download the resource if it has changed.
o PUT: Update an existing resource (or create a new one if it doesn't exist).
o DELETE: Delete the specified resource.
o TRACE, OPTIONS, CONNECT, PATCH: These verbs are for less common/advanced tasks,
so we won't cover them here.
Additional information can be encoded with the request (for example, HTML form data).
Information can be encoded as:
o URL parameters: GET requests encode data in the URL sent to the server by adding
name/value pairs onto the end of it — for example http://example.com?
name=Fred&age=11. You always have a question mark (?) separating the rest of the URL
from the URL parameters, an equals sign (=) separating each name from its associated
value, and an ampersand (&) separating each pair. URL parameters are inherently
19
"insecure" as they can be changed by users and then resubmitted. As a result URL
parameters/GET requests are not used for requests that update data on the server.
o POST data. POST requests add new resources, the data for which is encoded within the
request body.
o Client-side cookies. Cookies contain session data about the client, including keys that
the server can use to determine their login status and permissions/accesses to
resources.
Web servers wait for client request messages, process them when they arrive, and reply to the
web browser with an HTTP Response message. The response contains an HTTP Response status
code indicating whether or not the request succeeded (e.g. "200 OK" for success, "404 Not
Found" if the resource cannot be found, "403 Forbidden" if the user isn't authorized to see the
resource, etc.). The body of a successful response to a GET request would contain the requested
resource.
When an HTML page is returned it is rendered by the web browser. As part of processing, the
browser may discover links to other resources (e.g. an HTML page usually references JavaScript
and CSS files), and will send separate HTTP Requests to download these files.
Both static and dynamic websites (discussed in the following sections) use exactly the same
communication protocol/patterns.
20
It only takes one copy to use it in Individual copies are needed for each
Usability multiple projects or applications. project or application.
Flexibility There is less user control flexibility. Custom control flexibility is more
The user interface is fixed and cannot be The Custom Controls interface will be
User Interface
altered. changed.
Security
It involves the protection of information systems and the information processed, stored and
transmitted by these systems from unauthorized access, use, disclosure, disruption, modification or
destruction.
This includes the protection of personal information, financial information, and sensitive or
confidential information stored in both digital and physical forms. Effective information security
21
requires a comprehensive and multi-disciplinary approach, involving people, processes, and
technology.
Information Security is not only about securing information from unauthorized access.
Information Security is basically the practice of preventing unauthorized access, use, disclosure,
disruption, modification, inspection, recording or destruction of information.
Information can be a physical or electronic one. Information can be anything like Your details or we
can say your profile on social media, your data on mobile phone, your biometrics etc.
Thus Information Security spans so many research areas like Cryptography, Mobile Computing, Cyber
Forensics, Online Social Media, etc.
HTML Supports several ways of arranging items in lists. The most commonly used are:
• Ordered List (Numbered List)
• Unordered List (Bulleted List)
An Ordered List
</TITLE>
</HEAD>
<BODY>
<H1><U> Various Terms Used In Internet</U></H1>
<OL>
<LI> WWW-World Wide Web
<LI> URL-Uniform Resource Locator
<LI> HTTP-Hypertext Transfer Protocol
<LI> FTP-File Transfer Protocol
<LI> HTML-Hypertext Markup Language
</OL>
</BODY>
</HTML>
22
Unordered List also called as bulleted list, used to present list of items marked with bullets. An
unordered list starts with in <UL>followed by <LI> (List Item) tag. Use of <UL> is very similar to
<OL>(ordered list).
Example: Use of Unordered List and Various Attributes
<HTML>
<HEAD>
<TITLE> Use of Unordered List </TITLE>
</HEAD>
<BODY>
<UL>
<LI> FRUITS
<UL>
<LI> Banana
<LI> Jack
<LI> Orange
</UL>
<LI> VEGETABLE
<UL>
<LI> Potato
<LI> Cabbage
<LI> Tomato
</UL>
</UL>
</BODY>
</HTML>
23
20. Write briefly about XML schemas
XML Schema is an XML-based language used to create XML-based languages and
data models.
An XML schema defines element and attribute names for a class of XML documents.
The schema also specifies the structure that those documents must adhere to and
the type of content that each element can hold.
An XML schema describes the structure of an XML instance document by defining
what each element must or may contain.
An element is limited by its type. For example, an element of complex type can
contain child elements and attributes, whereas a simple-type element can only
contain text
24
private Color color = Color.green;
Compile the Bean, load it in the ToolBox, and create an instance in the BeanBox.
1. With the first method, simple naming conventions to infer the introspection
mechanisms to infer information about a bean.
2. In the second way, an additional class that extends the Beaninfo interface is provided that
explicitly supplies this information.
Introspection is the process of exposing the properties, methods, and events that a JavaBean
component supports. This process is used at run-time, as well as by a visual development tool at design-
time. The default behavior of this process allows for the automatic introspection of any Bean. A low-
level reflection mechanism is used to analyze the Bean’s class to determine its methods. Next it applies
25
some simple design patterns to determine the properties and events that are supported. To take
advantage of reflection, you only need to follow a coding style that matches the design pattern. This is
an important feature of JavaBeans. It means that you don’t have to do anything more than code your
methods using a simple convention. If you do, your Beans will automatically support introspection
without you having to write any extra code
Initialization:
After creating the instances, the servlet container calls the init() method and passes the servlet
initialization parameters to the init() method.
The init() must be called by the servlet container before the servlet can service any request. The
initialization parameters persist untill the servlet is destroyed. The init() method is called only
once throughout the life cycle of the servlet.
The servlet will be available for service if it is loaded successfully otherwise the servlet container
unloads the servlet.
26
Servicing the Request:
After successfully completing the initialization process, the servlet will be available for service. Servlet
creates seperate threads for each request. The sevlet container calls the service() method for servicing
any request. The service() method determines the kind of request and calls the appropriate method
(doGet() or doPost()) for handling the request and sends response to the client using the methods of the
response object.
27
cycle of the servlet. Calling the destroy() method indicates to the servlet container not to sent
the any request for service and the servlet releases all the resources associated with it. Java
Virtual Machine claims for the memory associated with the resources for garbage collection.
28
Make sure that you have not used System.exit() method anywhere
in your program
Do not display sensitive parameter values in web page like
password
25. How do you install the Java Software Development Kit? Explain the steps.
The JDK can be installed on the following Platforms:
1. Microsoft Windows
2. Linux
3. macOS
The website will contain the latest version for your corresponding system. For Windows, we’ll be
downloading the latest x64 Installer of Java SE Development Kit
If you are running Windows and installed the SDK in C:\jdk1.5.0_20, you would put the following line in
your C:\autoexec.bat file.
set PATH=C:\jdk1.5.0_20\bin;%PATH%
set JAVA_HOME=C:\jdk1.5.0_20
javac -version
29
The <jsp:useBean> action has a scope attribute you use to specify the scope for the
bean.
The <jsp:useBean> action ensures that the bean already exists in this scope or that a
new one is created and placed in the specified scope.
It first looks for a bean with the name specified by the id attribute in the specified scope.
If it already exists, for instance created by a previously invoked <jsp:useBean> action or
by a servlet, it does nothing.1
If it can't find it, it creates a new instance of the class specified by the class attribute and
makes it available with the specified name within the specified scope
Example :
Jsp code
<HTML>
<HEAD>
<TITLE>Getting a Property Value</TITLE>
</HEAD>
<BODY>
<H1>Getting a Property Value</H1>
<jsp:useBean id="bean1" class="beans.Test" /> The message is: <jsp:getProperty
name="bean1" property="message" />
<BR>
<jsp:setProperty name="bean1" property="message" value="Hello again!" />
Now the message is: <jsp:getProperty name="bean1" property="message" />
</body>
</html>
Test.java
package beans;
import java.io.Serializable;
public class Test implements Serializable
{
public Test()
{
}
private String message = "Hello from JSP!";
public void setMessage(String message)
{
this.message = message;
}
public String getMessage()
{
30
return this.message;
}
}
JavaBeans are classes that encapsulate many objects into a single object (the bean). It is a Java class
that should follow the following conventions:
1. Must implement Serializable.
2. It should have a public no-arg constructor.
3. All properties in java bean must be private with public getters and setter methods
// Java Program of JavaBean class
package geeks;
// Constructor
public Student()
{
}
31
In addition to window-content objects, JavaScript supports a small handful of "built-in" objects. These
built-in objects are available regardless of window content and operate independently of whatever page
Netscape has loaded.
String Object
Math Object
Date Object
String Object
String object is bona fide object and the string keyword is used to create new strings
For ex string objects
o Var myString = new String ();
o myString = “This is String”
o alert (“This is String”. Length())
Math Object
Math objects provides built in constants and methods to perform calculations with in the scripts
For ex, to return the valud of pi, you can use
Var pi = Math.PI;
Date Object
Date object is similar to the string object in that you create a new instances of an object
When you assign it to variable
The syntax for creating new date object is
VariableName = new Date(Parameters)
o Ex: Today = new Date();
You have several optional parameters to send to the date objects that are as follows,
o variableName = new Date()
o variableName = new Date(year, month, day)
o variableName = new Date(year, month, day, hours, minutes, seconds)
30. Explain about various types of List tags in HTML. -- Already covered
Orderedlist
Unordered list
32
o Entity Beans
o Session Beans
Session Beans
o It does not maintains a state of the client between multiple method calls
o It can be accessed by one client at a time
33
o In case of concurrent access, EJB container routes each request to different instance
o One can specify whether a bean is stateful or not in the bean's deployment
descriptor.
o Because of stateless session beans can supports multiple clients , they can offer
better scalability for applications that require large number of clients
Entity Beans
An “Entity bean” is a type of Enterprise Java Bean, that represents persistent data
maintained in data base.
Users Data can be saved to database via entity beans, and later on can be retrieved from the
database in the entity bean
Entity beans are normally used to manage complex coarse – grained persistent data for a
remote client
There are two types of entity beans and they are distinguished by how they manage
persistence
o Container Managed Persistence
o Bean Managed Persistence
Container Managed Persistence are Enterprise Bean that persists across the database
In this Method container take care of database calls
Bean Managed Persistence is a type of Entity Bean, where the programmer has to write the
code for database calls
It persists across multiple sessions and multiple clients
34
33. 13. (a)Describe servlet life cycle with neat diagram. – Already covered
Servlets are Java programs that runs on the java enabled web server or application server
They are used to handle request obtained from web server, process the request, produce the
response and then send response back to the web server
In Java to create applications we use servlets
To Create Java Servlets, We need to use Servlet API which contains all necessary interfaces and
classes
Servlet API has two packages namely
o Javax.servlet
o Javax.servlet.http
While the javax.servlet.http package contains the classes that are used when developing HTTP -
specific servlets
The HttpServlet is extended from GenericServlet base class and it implements the Servlet
interface. HttpServlet class provides a framework for handling the HTTP requests.
Classes available in javax.servlet.http package:
o Cookie
o Httpservlet
35
35. (b) Explain about various types of JDBC Drivers.
JDBC stands for Java Data Base Connectivity
JDBC drivers are the set of classes that enable java applications to communicate with database
JDBC drivers are divided in to 4 types
Each Types defines a JDBC driver implementation with higher level of platform independence,
performance and deployment administration
The four types of JDBC drivers are
o Type 1 - JDBC – ODBC Bridge
o Type 2 – Native API – Partially java technology enabled driver
o Type 3 – Net Protocol – Fully java technology enabled driver
o Type 4 – Native protocol – Fully Java technology enabled driver
36
Example of type 3 drivers are BEA’s Weblogic
These servers are especially used in applet deployment
Advantages
There is no need for vendor database library
Its highly portable, performance, and scalable
Disadvantages
Traversing the record set may take time, as the data comes from backend server
Advantages
It does not require any specific software to be installed on client or server
These drivers can be downloaded dynamically
Better performance than Type1 and Type 3 Drivers
Disadvantages
User needs different drivers for each database
Model
The Model in MVC Design pattern acts as Data Layer for the application
It represents business logic for an application and also contains state of the application
Its an object that contain data, that also carry logic to update the controller if data is changed
View
The View in MVC Design Pattern act as Presentation Layer of the application
As the name indicates, view represents the visualization of the data received from Model
37
View Layer consists of user Interface for the application
It sends the data requested to the client which is fetched from Model Layer by controller
Controller
It works on Both Model and view
Its uses to manage the flow of application, I,e data flow in the model object and to update the
view whenever data is changed
Its acts as an interface between model and view layer
The controller layer get the user requests from View layer and sends them to model layer for
data processing , once they are processed, the data are send back to controller and displayed in
view
10- Marks
1.Explain in detail about arrays in Javascript with suitable examples.
Array
Java Script Array is a data structure that allows you to store and organize multiple values with in
single variable
Its versatile and dynamic object
It can hold various data types including numbers, strings, objects, and even other arrays
Java script arrays are indexed as 0
First element of an array starts from 0th index and second element starts from 1st index and so
on
Declaring an array
There are basically two ways to create array
o Array constructor
o Array literal
Syntax:
Arrayname = [array1, array2….arrayn];
Example
Let name = [];
Console.log(name);
38
Let courses = [“HTML”,”CSS”,”JAVA”];
Console.log(courses);
O/p
[]
[[“HTML”,”CSS”,”JAVA”]
Syntax:
Let array = new array ();
Example
Creating an empty array
Let names = new array ();
Console.log(names);
Output
[]
[ 10, 20, 30 ]
39
CSS stands for Cascading Style Sheets
It’s a style sheet language which is used to describe the look and feel of a document written in
markup language
It provides an additional features to HTML
Its generally used with HTML page to change the style of webpages and UI.
There are three types of CSS
a. Inline Style sheet
b. Internal or embedded style sheet
c. External style sheet
<BODY>
<P> PARAGRAPH </P>
40
Here whenever paragraph tag is used in the page, it appears in the properties specified
</BODY>
</HTML>
EXAMPLE
DTD
Document Type Definition is DTD
DTD is a type of schema
The purpose of DTDs is to provide framework for validating XML documents
DTD is, a set of rules defining relationships within a document
DTDs can be "internal" (within a document) or "external" (links to another document).
Elements
Elements are the main building blocks of both xml and html documents
Examples of html elements are “body” & “table”
41
Example of xml elements are “note” & “message”
Tags
Tags are used to markup elements
Starting tag like <element name > mark up the beginning of elements and ending tag like
</element name> mark up the end of an element
Ex: HTML tags <body>……….. </body>
Ex: XML Tags <message> ……</message>
Attributes
Attributes provides an extra information about elements
A cookie is a http mechanism that is used for maintaining specific user settings and managing
state. A cookie is a simple mechanism which is used to store and retrieve user specified info on
the web.
When a httpserver receives an request the server may choose to return some state information
that is stored by a cookie enabled client.
This state information includes URL range whenever an Client receives http request it checks the
URL of the request against the URL range of all stored cookies.
For Example,
A servlet uses the getCookies() method of HTTPServletRequest to retrieve cookies as request.
The addCookie() method of HTTPServletResponse sends a new cookie to the browser.
You can set the age of cookie by setMaxAge() method.
Here is the code which defines cookie and shows how to set the maximum age of cookie.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class UseCookies extends HttpServlet
{
public void doGet ( HttpServletRequest request,
HttpServletResponse response )throws ServletException, IOException
{
PrintWriter out;
response.setContentType("text/html");
out = response.getWriter();
Cookie cookie = new Cookie("CName","Cookie Value");
cookie.setMaxAge(100);
42
response.addCookie(cookie);
out.println("<HTML><HEAD><TITLE>");
out.println(" Use of cookie in servlet");
out.println("</TITLE></HEAD><BODY BGCOLOR='cyan'>");
out.println(" <b>This is a Cookie example</b>");
out.println("</BODY></HTML>");
out.close();
}
}
In the above example, a servlet class UseCookies defines the cookie class.
Here the age of cookie has been set as setMaxAge(100). If its value is set to 0, the cookie will delete
immediately.
After the time provided been expired, cookie will automatically deleted.
Event Description
Handler
onBlur It executes when the input focus leaves the field of a text, textarea or a select option.
onChange It executes when the input focus exits the field after the user modifies its text.
onClick In this, a function is called when an object in a button is clicked, a link is pushed, a checkbox is checked or
image map is selected. It can return false to cancel the action.
43
onFocus It executes when input focus enters the field by tabbing in or by clicking but not selecting input from the
field.
onMouseOver The JavaScript code is called when the mouse is placed over a specific link or an object.
onMouseOut The JavaScript code is called when the mouse leaves a specific link or an object.
onReset It executes when the user resets a form by clicking on the reset button.
onSelect It executes when the user selects some of the text within a text or textarea field.
Here we are illustrating the installation process only for Windows. Steps involved in installation and
configuration process for Tomcat 6.0.10 are illustrated below:
Step 1:
Installation of JDK: Don't forget to install JDK on your system (if not installed) because any tomcat
requires the Java 1.5 (Java 5) and Java 1.6 (Java 6) and then set the class path (environment variable) of
JDK.
Step 2: Setting the class path variable for JDK: Two methods are there to set the classpath.
1. Set the class path using the following command.
Step 3:
Now it's time to shift on to the installation process of Tomcat 6.0.10. It takes various steps for installing
and configuring the Tomcat 6.0.For Windows, Tomcat comes in two forms : .zip file and the Windows
installer (.exe file). Here we are exploring the installation process by using the .exe file. The directory C:\
44
apache-tomcat-6.0.10 is the common installation directory as it is pre-specified C:\ as the top-level
directory. First unpack the zipped file and simply execute the .exe file.
The above shown screen shot is the first one shown in the installation process. Just click on the Next
button to proceed the installation process.
45
46
of the people change the port number to 80 because in this case the user is not required to specify the
port number at request time. But we are using here the default port number as 8080. Choose the user
name and password as per your convenience. We can change the port number even the installation
process is over. For that, go to the specified location as " Tomcat 6.0 \conf \server.xml ". Within the
server.xml file choose "Connector" tag and change the port number.
e.g While using the port number 8080, give the following request in the address bar as:
Default Port: http//localhost:8080/index.jsp
In case of port number number 80 just type the string illustrated below in the address bar:
New Port: http://localhost/index.jsp
Note that we do no need to specify any port number in the URL.
Now click on the Next button to proceed the installation process.
47
48
After successfully installing, a shortcut icon to start the tomcat server appears in the icon tray of the task
bar as shown above. Double clicking the icon displays the window of Apache Manager for Tomcat. It will
show the "Startup type" as manual since we have changed the destination folder for tomcat during the
installation process. Now we can configure the other options like "Display name" and "Description" .We
can also start, stop and restart the service from here
step 4:
Setting the JAVA_HOME Variable: Purpose of setting the environment variable JAVA_HOME is to specify
the location of the java run time environment needed to support the Tomcat else Tomcat server does
49
not run. This variable contains the path of JDK installation directory. Note that it should not contain the
path up to bin.
set JAVA_HOME=C:\Program Files\Java\jdk1.5.0_08
Here, we have taken the URI path according to our installation convention
For Windows XP, Go through the following steps:
Start menu->Control Panel->System->Advanced tab->Environment Variables->New->set the Variable
Name as JAVA_HOME and Variable Value as C:\Program Files\Java\jdk1.6.0 and then click on the entire
three ok buttons one by one. It will set the JDK path.
Now , Start the Tomcat Server : Start the tomcat server from the bin folder of Tomcat 6.0 directory by
double clicking the " tomcat6.exe " file. You can also create a shortcut of this .exe file at your desktop.
Stop the Tomcat Server: Stop the server by pressing the "Ctrl + c" keys.
A request handler provided by the application developer that is used to mapped to a particular URI
A response handler which is used to transfer the control to another resource which will be responsible
for completing the response
A tag library which helps developers to create the interactive form based applications with server pages
Struts provides you the basic infrastructure infrastructure for implementing MVC allowing the
developers to concentrate on the business logic
50
the users and accepting the input from them. They are responsible for
displaying the information provided by the model components. Mostly we
use the Java Server Pages (JSP) for the view presentation. To extend the
capability of the view we can use the Custom tags, java script etc.
1. With the first method, simple naming conventions to infer the introspection mechanisms to
infer information about a bean.
2. In the second way, an additional class that extends the Beaninfo interface is provided that
explicitly supplies this information.
Introspection is the process of exposing the properties, methods, and events that a JavaBean
component supports. This process is used at run-time, as well as by a visual development tool at design-
time. The default behavior of this process allows for the automatic introspection of any Bean. A low-
level reflection mechanism is used to analyze the Bean’s class to determine its methods. Next it applies
some simple design patterns to determine the properties and events that are supported. To take
advantage of reflection, you only need to follow a coding style that matches the design pattern. This is
an important feature of JavaBeans. It means that you don’t have to do anything more than code your
methods using a simple convention. If you do, your Beans will automatically support introspection
without you having to write any extra code
51
import java.beans.PropertyDescriptor;
public class SimpleBean
{
private final String name = "SimpleBean";
private int size;
public String getName()
{
return this.name;
}
public int getSize()
{
return this.size;
}
public void setSize( int size )
{
this.size = size;
}
public static void main( String[] args ) throws IntrospectionException
{
BeanInfo info = Introspector.getBeanInfo( SimpleBean.class );
for ( PropertyDescriptor pd : info.getPropertyDescriptors() )
System.out.println( pd.getName() );
}
}
This example creates a non-visual bean and displays the following properties derived from the BeanInfo
object:
class
name
size
Limitations of Ajax.
- Back functionality cannot work because the dynamic pages don’t register themselves to the
browsers history engine. Hence the need of Iframe becomes essential.
- The page cannot be bookmarked if implemented using Ajax.
- If java script is disabled , Ajax will not work
- Because different components of the pages are loaded at different times, response time may
be slow.
- Because different components of the pages are loaded at different times it may create
confusion for the user.
52
Security Issues
AJAX is the most commonly used web technique to send and receive data to and from the web server
asynchronously without disturbing the functionality of the other components of the client-side
application. Although AJAX itself does not provide any security vulnerabilities, still we have to keep some
security measurements while implementing AJAX. The security measurements are –
Cross-Site Scripting(XSS) − AJAX applications should be vulnerable to XSS attacks. If proper input
validation and output encoding are not implemented, then a hacker can easily inject malicious scripts
inside the AJAX response. These malicious scripts are used to steal sensitive data from the system or can
manipulate the content.
Cross-Site Request Forgery(CSRF) − In this attack, the attacker tricks the browser by doing unwanted
actions with the help of an authentication session. It can exploit the AJAX request and can perform
unauthorized actions.
Insecure Direct Object References(IDOR) − The request generally accesses the specified resource from
the server with the help of a unique identifier. But if the attacker gets this identifier then it can easily
manipulate or can access unauthorized resources
Content Security Policies(CSP) − It is a policy which helps users/developers to save themselves from
malicious activities or unauthorized access.
Server-Side validation − Server-side validation is very important because it ensures that the submitted
data meets the specified criteria and it is safe for further process.
Secure Session Management − The AJAX application should properly maintain user sessions and session
tokens to save the session from attacks
Input Validation and Sanitization − Server should perform validation and sanitization of the data
received from the client side to prevent attacks.
Regular Update and Security − As we know that AJAX uses external libraries or frameworks. So keeping
them up to date is an important task. To avoid various vulnerabilities and improve the security of the
application.
53
Beginners often get confused with JRE and JDK, if you are only interested in running Java
programs on your machine then you can easily do it using Java Runtime Environment.
However, if you would like to develop a Java-based software application then along with JRE
you may need some additional necessary tools, which is called JDK
JDK is a combination of JRE+ Development Tools
Java Development Kit is an implementation of one of the JAVA platform
Contents of JDK
The JDK has a private Java Virtual Machine (JVM) and a few other resources necessary for the
development of a Java Application.
JDK contains:
Java Runtime Environment (JRE),
An interpreter/loader (Java),
A compiler (javac),
An archiver (jar) and many more.
Below there is a comprehensive list of mostly used components of Jdk which are very useful
during the development of a java application.
Use
Component
jdb Debugger,
54
10. Explain about functions of javax.sql package
This package provides the APIs for accessing and processing data which is stored in the database
especially relational database by using the java programming language.
It includes a framework where we different drivers can be installed dynamically to access different
databases especially relational databases.
2 Marks
Keyhole Markup Language (KML) is a markup language based on XML and useful for describing and
implementing 2D and 3D visual shapes on HTML-based browsers.
55
15. Differentiate cookies and session variables.
Cookies expire after the user The session ends when the
Expiry specified lifetime. user closes the browser or
logs out of the program.
56
Request Object
Session Object
Out Object
PageContext Object
Application Object
Config Object
Page Object
Exception Object
21. What are the two major protocols for accessing email from servers?
Email protocols are a collection of protocols that are used to send and receive
emails properly.
The email protocols provide the ability for the client to transmit the mail to or
from the intended mail server.
Three basic types of email protocols involved for sending and receiving mails are:
SMTP Simple Mail Transfer Protocol Used to send mails over the internet
POP3 Post Office Protocol Used to retrieve mail for single client. POP 3 version is the
current version of POP used
IMAP Internet Message Access Protocol Used to retrieve mails for multiple clients
57
22. Define HTTP protocol.
HTTP stands for HyperText Transfer Protocol.
It is a protocol used to access the data on the World Wide Web (www).
The HTTP protocol can be used to transfer the data in the form of plain text,
hypertext, audio, video, and so on.
WSDL Stands for Web Services Description Language and its XML Based language
WSDL is used to describe Web services
The WSDL file is used to describe in a nutshell what the web service does and gives the client all
the information required to connect to the web service and use all the functionality provided by
the web service.
The WSDL file contains the location of the web service and
The methods which are exposed by the web service
The WSDL file itself can look very complex to any user, but it contains all the necessary
information that any client application would require to use the relevant web service.
UDDI is an XML-based standard for describing, publishing, and finding web services.
58
19. What is the role of server?
Server roles – servers can be configured to perform a number of roles. The applications that the server is
running specify the particular server’s role. Servers typically need services and additional features
installed to perform its specific role. When compared to workstations, servers have more disk space and
memory and faster processors. The server’s role determines the hardware that servers require. A few
common server roles are listed below
Domain controller
Database server
Backup server
File server
Print server
Infrastructure server
Web server
E-mail server
59
Its portable its written in Java, with no platform native code
25.
60