Professional Documents
Culture Documents
Advanced Internet Technologies (MCS-051)
Advanced Internet Technologies (MCS-051)
Q1. (a) What are the main objectives of session tracking? What are the two ways to
handle session tracking ? Explain with the help of an example.
Answer 1(a) : Session tracking enables you to track a user's progress over multiple servlets
or HTML pages, which, by nature, are stateless.
1. User Authorization
Users can be authorized to use the web application in different ways. Basic concept is that the
user will provide username and password to login to the application. Based on that the user can
be identified and the session can be maintained.
Session tracking API is built on top of the first four methods. This is inorder to help the
developer to minimize the overhead of session tracking. This type of session tracking is
provided by the underlying technology.
Q1(b) What are the major differences between a session and a cookie ?
Ans 1(b) : Cookies and Session are used to store the information.Cookies are store only client
side while Session stored the information client side as well as server side. A session creates a
file in a temporary directory on the server where registered session variables and their values
are stored.
Question 2. Assume there is a table named students which created is Oracle database
having the
following fields:
- E-number
- S-name
- Name - of school
- Programme
- Year of admission
- Date of birth
(a) Enter at least 5 records and write a servlet code which will display all the fields of
the above table and all records entered in the table in a tabular form.
(b) Answer the following SQL queries related to the student table.
(i) List all the student enrolled in a school of computer sciences in the year 2016.
(ii) Count the number of students registered in BCA Programme.
(iii) List all the students below the age of 25 years.
Answer 2:
(A)
Create TABLE [dbo].[Students](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Enrolment_Number] [bigint] NOT NULL,
[S_NAME] [varchar](50) NULL,
[Name_Of_School] [varchar](150) NULL,
[Programme] [varchar](50) NULL,
[Age] [varchar](50) NULL,
[Year_Of_Admission] [varchar](50) NULL,
[Stream] [varchar](100),
[CreatedDate] [datetime],
PRIMARY KEY(Enrolment_Number)
)
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034567,'Ravi Bhaskar','IGNOU','MCA','25 years','july 2016','computer
sciences',getdate())
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034577,'Diwakar','IGNOU','BCA','25 years','year 2016','computer
sciences',getdate())
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034557,'Vidatri Shing','IGNOU','MCA','25 years','july 2016','computer
sciences',getdate())
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034537,'Gautam','IGNOU','MCA','25 years','july 2016','computer
sciences',getdate())
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034527,'Ravi Jaiswal','IGNOU','BCA','25 years','year 2016','computer
sciences',getdate())
insert into
Students(Enrolment_Number,S_NAME,Name_Of_School,Programme,Age,Year_Of_Admission,Stream,
CreatedDate)Values(157034507,'Kaushal','IGNOU','MCA','24 years','july 2015','computer
sciences',getdate())
import javax.servlet.*;
import java.io.*;
import java.sql.*;
import javax.servlet.http.*;
public class Employee extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
IOException, ServletException
{
res.setContentType("text/Html");
PrintWriter pw = res.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:dsn");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from students");
String tr="";
while(rs.next()){
tr=tr+"<tr>";
tr=tr+"<td>"+rs.getString(1)+"</td>";
tr=tr+"<td>"+rs.getString(2)+"</td>";
tr=tr+"<td>"+rs.getString(3)+"</td>";
tr=tr+"<td>"+rs.getString(4)+"</td>";
tr=tr+"<td>"+rs.getString(5)+"</td>";
tr=tr+"</tr>";
}
String table="<table border='1'>"+tr+"</table>";
pw.write(table);
pw.close();
con.close();
}catch(Exception e)
{
pw.write(""+e);
}
}
}
(B)
Q3. Differentiate between the two different types of servlets? What are the two
interfaces in
the servlet API.
Answer 3 : There are two servlet types, generic and HTTP: Generic servlets are
sub classes of javax.servlet.GenericServlet . ... It has built-in HTTP protocol support. The
doGet and doPost methods are used to handle client requests (GET or POST requests)
Every Servlet must implement the java.servlet.Servlet interface, you can do it by extending
one of the following two classes: javax.servlet.GenericServlet or javax.servlet.http.HttpServlet .
The first one is for protocol independent Servlet and the second one for http Servlet.
Answer 4(A) : In this JSP tags are used to insert JAVA code into HTML pages.
It is an advanced version of Servlet Technology. It is a Web based technology
helps us to create dynamic and platform independent web pages. ... JSP is first
converted into servlet by JSP container before processing the client's request.
JavaServer Pages (JSP) is a technology for developing Webpages that supports
dynamic content. This helps developers insert java code in HTML pages by making
use of special JSP tags, most of which start with <% and end with %>.
A JavaServer Pages component is a type of Java servlet that is designed to fulfill
the role of a user interface for a Java web application. Web developers write JSPs
as text files that combine HTML or XHTML code, XML elements, and embedded JSP
actions and commands.
(b) Define custom tags in JSP and describe components that make
up a tag library in JSP.
Answer 4(B): A custom tag is a user-defined JSP language element. When a JSP
page containing a custom tag is translated into a servlet, the tag is converted to
operations on a tag handler. The web container then invokes those operations when
the JSP page’s servlet is executed.
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://psvsolution.com/j2ee/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>simple</short-name>
<uri>http://tomcat.apache.org/example-taglib</uri>
<tag>
<name>today</name>
<tag-class>com.javatpoint.sonoo.MyTagHandler</tag-class> </tag> </taglib>
Components:
Q5. Assume there is product table in the company’s database created in Oracle
with the
following fields:
- Product - ID
- Product - name
- Year of manufacturing
- Product cost
Write a code connecting JSP to Oracle database through JDBC and perform the
following
operations:
- Insert 10 records in the database
- Modify these records
- Display the product name which was manufactured before 2017.
- Display the product ID which costs more than Rs. 50000 and manufactured after
2017.
Answer 5:
CREATE TABLE Products
(
ID int Identity(1,1)NOT null,
Product_ID int NOT NULL,
Product_Name varchar2(100) NOT NULL,
Year_of_Manufacturing varchar2(50) null,
Products_Cost decimal null,
CONSTRAINT Products_pk PRIMARY KEY (Product_ID)
)
connecting JSP to Oracle database through JDBC
import java.sql.*;
public class connect
{
public static void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
// Establishing Connection
Connection con = DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:orcl", "login1", "pwd1");
if (con != null)
System.out.println("Connected");
else
System.out.println("Not Connected");
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
INSERT INTO Products VALUES (1, 'Bags', '2018', 12000)
INSERT INTO Products VALUES (2, 'TV', '2014', 25000)
INSERT INTO Products VALUES (3, 'Disney', '2013', 18000)
INSERT INTO Products VALUES (4, 'Bike', '2012', 49000)
INSERT INTO Products VALUES (5, 'Teblet', '2014', 12000)
INSERT INTO Products VALUES (6, 'Laptop', '2015', 13000)
INSERT INTO Products VALUES (7, 'Shose', '2016', 12000)
INSERT INTO Products VALUES (8, 'Shampoo', '2018', 12000)
INSERT INTO Products VALUES (9, 'Car', '2016', 120000)
INSERT INTO Products VALUES (10, 'Earphone', '2016', 1200)
Q6. What is the need of connecting servlet and JSP and explain the process
through a programme template.
Answer 6 : Servlet is html in java whereas JSP is java in html. Servlets run faster compared
to JSP JSP is a webpage scripting language that can generate dynamic content while
Servlets are Java programs that are already compiled which also creates dynamic web content.
In MVC, jsp acts as a view and servlet acts as a controller.
Answer 7: HTTP supports the use of several authentication mechanisms to control access
to pages and other resources. These mechanisms are all based around the use of
the 401 status code and the WWW-Authenticate response header.
Basic The client sends the user name and password as unencrypted base64
encoded text. It should only be used with HTTPS, as the password can be
easily captured and reused over HTTP.
Digest The client sends a hashed form of the password to the server. Although, the
password cannot be captured over HTTP, it may be possible to replay requests
using the hashed password.
NTLM This uses a secure challenge/response mechanism that prevents password capture
or replay attacks over HTTP. However, the authentication is per connection and will
only work with HTTP/1.1 persistent connections.
Basic and Digest authentication use a four step process to authenticate users.
First HTTP client makes a request to the web server. ... And then client displays a
dialog box to take username and password as input. Once the credentials has been
enter the client sends it using the Authorization header
Q8. Discuss advantage of using entity bean for database operations over
directly using
o Separation of business logic from your database access logic makes Entity
Beans a better choice than session beans using JDBC.
o If you are using Entity beans you dont need to worry about database
transaction handling, database connection pooling etc. which are taken care by
the ejb container. But in case of JDBC you have to explicitly do transaction
handling & connection pooling.
o The great thing about the entity beans is that beans are container managed,
whenever the connection is failed during the transaction processing, the
database consistancy is mantained automatically. the container writes the data
stored at persistant storage of the entity beans to the database again to
provide the database consistancy. where as in jdbc api, developers has to do
manually.
Q9. (i) Explain the difference between external entity and internal XML
entities
(ii) How Java Beans and enterprise java beans are different?
entity, e.g.
Q10. (i) Design XML DTD for an organisation that contains employee
information. An
employee element has fields: first name, last name, age, address and
department. The
address element has fields: cities, state and pin code.
Answer 10(1):
<document>
<employee>
<firstname>Jitendra kumar</firstname>
<lastname>Maurya</lastname>
<age>20</age>
<Department>IT Department<Department
</employee element>
<address element>
<city>New Delhi</city>
<state>Delhi</state>
<pincode>110092</pincpode>
</addresselements>
</employee>
</document>
Answer 10(ii):
An XML document validated against a DTD is both "Well Formed" and "Valid".