MCS-051 Solved Assignments

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

For more IGNOU Solved Assignments visit – www.IGNOUHelp.

in

Get Daily Updates by Facebook:

https://www.facebook.com/IGNOUHelp.in
---------------------------------------------------------------------------------------------------------------------
------------------

Course Code
:
MCS-051
Course Title
:
Advanced Internet Technologies
Assignment Number
:
MCA (5)/051/Assign/2013
Maximum Marks
:
100
Weightage
:
25%

There are eight questions in this assignment. Each question carries 10 marks. Rest
20 marks are for viva-voce. Answer all the questions. You may use illustrations and
diagrams to
enhance the explanations. Please go through the guidelines regarding assignments
given in the Programme Guide for the format of presentation.

Question1:

Assume that there is a table named as product in oracle with


(10 marks)
the following fields (Prod-ID, Product-name, Price, Vender-name) Write a
Java Programme to insert and then display the records of this table using JDBC.

Answer:

import java.sql.*;

public class jdbcoracle {

public static void main(String[] args) {


try {
Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {
e.printStackTrace();
return;
}

Connection connection = null;

try {

connection =

DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","lokesh")
; try {

String insertTableSQL ="INSERT INTO PRODUCT Values(?,?,?,?)";


PreparedStatement preparedStatement = null;

preparedStatement = connection.prepareStatement(insertTableSQL);
preparedStatement.setInt(1,10004);

------------------------------------------------------------------------------------------------------------
--------

2|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

preparedStatement.setString(2,"Moisturizer");
preparedStatement.setInt(3,45);
preparedStatement.setString(4,"Ayur Herbal Limited");

preparedStatement.executeUpdate();
System.out.println("Record inserted sucessfylly.");
preparedStatement.close();
}

catch (SQLException s)
{
System.out.println("Record not inserted sucessfylly.");
}

try {
Statement st = connection.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM product");

while (res.next()) {
int i = res.getInt("Product-ID");
String n = res.getString("Product-
name"); int p = res.getInt("Price");
String v = res.getString("Vender-name");

System.out.println("Product-ID:" + i + "Product-name:" +
n + "Price:" + p + "Vender-name:" + v);
}
connection.close();
st.close();
res.close();
}
catch (SQLException s){ System.out.println("SQL
code does not execute.");
}

} catch (SQLException e)
{ e.printStackTrace();
return;
}

if (connection == null) {
System.out.println("Failed to fetch records from oracle database");
}
}

------------------------------------------------------------------------------------------------------------
--------
3|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

Output of the above program:


Question 2:

(a) Write an XML DTD to represent the Grade Card of a student


(5 marks)
which contains:
(i) Name- Last, Middle, and First
(ii) Subjects- Five subjects
(iii) Assignments marks
(iv) Total Marks
(v) Result- Pass/Fail

Answer:

XML Code for Grade Card:

<?xml version="1.0"?>
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?

------------------------------------------------------------------------------------------------------------
--------

4|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

<!-- grade.xml -->


<!-- Representing the Grade Card of student in XML document -->
<!DOCTYPE grade SYSTEM grade.dtd">
<student>
<grade enroll="011223344">
<name>
<lname>SINGH</lname>
<mname>CHANDRA</mname>
<fname>LOKESH</fname>
</name> <subject>
<sub_a>MCS011</sub_a>
<sub_b>MCS012</sub_b>
<sub_c>MCS013</sub_c>
<sub_d>MCS014</sub_d>
<sub_e>MCS015</sub_e>
</subject>
<sub_marks>
<marks_a>90</marks_a>
<marks_b>91</marks_b>
<marks_c>92</marks_c>
<marks_d>93</marks_d>
<marks_e>94</marks_e>
</sub_marks>
<assinment_marks>
<assign_a>95</assign_a>
<assign_b>96</assign_b>
<assign_c>97</assign_c>
<assign_d>98</assign_d>
<assign_e>99</assign_e>
</assignment_marks>
<total_marks>446</total_marks>
<result>Pass</result>
</grade>
<content>This is system generated Grade Card has not any leagle value</content>
</student>

DTD Code for XML Grade Card:

<?xml version="1.0" rmd="internal"?>


</ELEMENT student(grade +,content *)>
<!Element grade(name, subject, sub_marks, assignment_marks, total, result)>

<!ATTLIST grade enroll CDATA #IMPLIED>

<!Element name(lname, mname,


lname)> <!Element lname(#PCDATA)>
<!Element mname(#PCDATA)>
<!Element fname(#PCDATA)>

------------------------------------------------------------------------------------------------------------
--------

5|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

<!Element subject(sub_a, sub_b, sub_c, sub_d, sub_e)>


<!Element sub_a(#PCDATA)>
<!Element sub_b(#PCDATA)>
<!Element sub_c(#PCDATA)>
<!Element sub_d(#PCDATA)>
<!Element sub_e(#PCDATA)>

<!Element sub_marks(marks_a, marks_b, marks_c, marks_d,


marks_e)> <!Element marks_a(#PCDATA)>
<!Element marks_b(#PCDATA)>
<!Element marks_c(#PCDATA)>
<!Element marks_d(#PCDATA)>
<!Element makrs_e(#PCDATA)>

<!Element assignment_marks(assign_a, assign_b, assign_c, assign_d, assign_e)>


<!Element assign_a(#PCDATA)>
<!Element assign_b(#PCDATA)>
<!Element assign_c(#PCDATA)>
<!Element assign_d(#PCDATA)>
<!Element assign_e(#PCDATA)>

<!Element total_marks(#PCDATA)>
<!Element result(#PCDATA)>
<!Element content(#PCDATA)>

(b) How does Session bean different from Entity bean in terms
of (5 marks)
object sharing and failure recovery?

Answer:

Different from Entity bean in terms of object sharing and failure recovery:

Functional Area
Session Bean
Entity Bean
Object state
Maintained by the container in
Maintained in the database or

the main memory across


other resource manager.

transactions. Swapped to
Typically cached in the

secondary storage when


memory in a transaction.

deactivated.

Object sharing
A session object can be used
An entity object can be shared

by only one client.


by multiple clients. A client

may pass an object reference to


another client.
State externalisation
The container internally
The entity object's state is

maintains the session object's


typically stored in a database.

state. The state is inaccessible


Other programs, such as an

to other programs.
SQL query, can access the

state in the database.


Transactions
The state of a session object
The state of an entity object is

------------------------------------------------------------------------------------------------------------
--------

6|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

can be synchronised with a


typically changed
transaction but is not
transactionally and is
recoverable.
recoverable.
Failure recovery
A session object is not
An entity object survives the
guaranteed to survive failure
failure and the restart of its
and restart of its container. The container. A client can
references to session objects
continue using the references
held by a client becomes
to the entity objects after the
invalid after the failure.
container restarts.

Question 3:

Explain four basic mechanisms through which a web client


can (10 marks)
authenticate a user to a web server during HTTP authentications.

Answer:
A web client can authenticate a user to a web server using one of the following
mechanisms: a) HTTP Basic Authentication b)

HTTP Digest Authentication c)

Form Based Authentication


d) HTTPS Client Authentication

a) HTTP Basic Authentication:

HTTP Basic Authentication, which is based on a username and password, is the


authentication mechanism defined in the HTTP/1.0 specification. A web server requests a web
client to
authenticate the user. As a part of the request, the web server passes the realm (a string)
in which the user is to be authenticated. The realm string of Basic Authentication does not have
to reflect any particular security policy domain (confusingly also referred to as a realm). The web
client obtains the username and the password from the user and transmits them to the web server.
The web server then authenticates the user in the specified realm. Basic Authentication is not a
secure authentication as user passwords are sent in simple base64 ENCODING (not
ENCRYPTED !),
and there is no provision for target server authentication. Additional protection
mechanism can be applied to mitigate these concerns: a secure transport mechanism (HTTPS), or
security at the network level (such as the IPSEC protocol or VPN strategies) can be deployed.

b) HTTP Digest Authentication:

Similar to HTTP Basic Authentication, HTTP Digest Authentication authenticates a user


based on a username and a password. However, the authentication is performed by transmitting the
password in an ENCRYPTED form, which is much MORE SECURE than the simple
base64
encoding used by Basic Authentication, e.g., HTTPS Client Authentication. As Digest
Authentication is not currently in widespread use, servlet containers are encouraged but
NOT
REQUIRED to support it.

------------------------------------------------------------------------------------------------------------
--------

7|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

c) Form Based Authentication:

The look and feel of the ‗login screen' cannot be varied using the web browser's built in
authentication mechanisms. This form based authentication mechanism allows a developer
to
CONTROL the look and feel of the login screens. The web application deployment
descriptor, contains entries for a login form and error page. The login form must contain fields
for entering a username and a password. These fields must be named j_username and
j_password, respectively.

When a user attempts to access a protected web resource, the container checks the user's
authentication. If the user is authenticated and possesses authority to access the resource,
the requested web resource is activated and a reference to it is returned. If the user is not
authenticated, all of the following steps occur:

1) The login form associated with the security constraint is sent to the client and the
URL path triggering the authentication stored by the container.
2) The user is asked to fill out the form, including the username and password fields.
3) The client posts the form back to the server.
4) The container attempts to authenticate the user using the information from the form.
5) If authentication fails, the error page is returned using either a forward or a redirect,
and the status code of the response is set to 200.
6) If authentication succeeds, the authenticated user's principal is checked to see if it is
in an authorised role for accessing the resource.
7) If the user is authorised, the client is redirected to the resource using the stored URL
Path.
The error page sent to a user that is not authenticated contains information about the
failure. Form Based Authentication has the same lack of security as Basic Authentication since
the user
password is transmitted as a plain text and the target server is not. Authenticated. again
additional protection can alleviate some of these concerns: a secure transport mechanism
(HTTPS), or
security at the network level (such as the IPSEC protocol or VPN strategies) are applied
in some deployment scenarios.

Form based login and URL based session tracking can be problematic to implement.
Form based login should be used only when, sessions are being maintained by cookies Or by
SSL session information.

d) HTTPS Client Authentication:

End user authentication using HTTPS (HTTP over SSL) is a strong


authentication mechanism.
This mechanism requires the user to possess a Public Key Certificate (PKC). Currently,
PKCs are useful in e-commerce applications and also for a single sign-on from within the
browser. Servlet containers that are not J2EE technology compliant are not required to support
the HTTPS protocol.
Client-certificate authentication is a more secure method of authentication than either
BASIC or FORM authentication. It uses HTTP over SSL, in which the server and, optionally, the
client authenticate one another with Public Key Certificates. Secure Sockets Layer (SSL)
provides data encryption, server authentication, message integrity, and optional client
authentication for a CP/IP
connection. You can think of a public key certificate as the digital equivalent of a passport. It
is issued by a trusted organisation, which is known as a certificate authority (CA), and provides
identification for the bearer. If, you specify client-certificate authentication, the Webserver will
authenticate the client using the client's X.509 certificate, a public key certificate that conforms to a
standard that is defined by X.509 Public Key Infrastructure (PKI). Prior to running an

------------------------------------------------------------------------------------------------------------
--------

8|P ag e
www.IGNOUHelp.in

------------------------------------------------------------------------------------------------------------
---------------------------

application that uses SSL, you must configure SSL support on the server and set up the
public key certificate.

Question 4:
(i) What do you mean by XML parsing? Briefly describe the parser
(5 marks)
involved with XML.

Answer:

An XML parser (or XML processor) is the software that determines the content and
structure of an XML document by combining XML document and DTD (if any present). Figure
below shows a simple relationship between XML documents, DTDs, parsers and applications.
XML parser is the software that reads XML files and makes the information from those files
available to applications and other programming languages. The XML parser is responsible for
testing whether a document is well-formed and, if, given a DTD or XML schema, whether will
also check for validity (i.e., it determines if the document follows the rules of the DTD or
schema). Although, there are many XML parsers we shall discuss only Microsoft's parser used
by the Internet explorer and W3C's parser that AMAYA uses.

XML
XML XML
DTD XML
Application
Document
(Optional
Parser

)
(E.g. AMAYA)

XML Document and their Corresponding DTDs are Parsed and sent to Application
(ii) Compare and contrast SSL and
TLS. (5 marks)

Answer:

Secure Socket Layer (SSL)/Transport Layer Security (TLS):

Secure Socket Layer (SSL) and Transport Layer Security (TLS), its successor, are
cryptographic protocols which provide secure communication on the Internet for as e-
mail, internet faxing, and other data transfers.

SSL provides endpoint authentication and communication privacy over the Internet using
cryptography. In typical use, only the server is authenticated (i.e. its identity is ensured)
while the client remains unauthenticated; mutual authentication requires public key
infrastructure (PKI) deployment to clients. The protocols allow client/server applications to
communicate in a way designed to prevent eavesdropping, tampering, and message forgery.

In cryptography, message forgery is the sending of a message to deceive the recipient of


whom the real sender is. A common example is sending a spam e-mail from an address
belonging to
someone else.

------------------------------------------------------------------------------------------------------------
--------

9|P ag e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

SSL involves three basic phases:


1) Peer negotiation for algorithm support,
2) Public key encryption-based key exchange and certificate-based authentication, and
3) Symmetric cipher-based traffic encryption. Web Security Concepts

During the first phase, the client and server negotiation uses cryptographic algorithms.
Current implementations support the following choices:
• For public-key cryptography: RSA, Diffie-Hellman, DSA or Fortezza;
• For symmetric ciphers: RC2, RC4, IDEA, DES, Triple DES or AES; •
For one-way hash functions: MD5 or SHA.
TLS/SSL have a variety of security measures:
• Numbering all the records and using the sequence number in the MACs. •
Using a message digest enhanced with a key.
• Protection against several known attacks (including man in the middle attacks), like those
involving a downgrade of the protocol to previous (less secure) versions, or weaker cipher suites.
• The message that ends the handshake (―Finished‖) sends a hash of all the exchanged
data seen by both parties.
• The pseudo random function splits the input data in 2 halves and processes them with
different hashing algorithms (MD5 and SHA), then XORs them together. This way it protects
itself in the event that one of these algorithms is found to be vulnerable.

Question 5:

(i) With the help of a sample code. Describe the use of


SSL (6 marks)
authentication in Java Client.

Answer:

SSL Authentication in Java Clients: JSSE (Java Secure Socket Extesnsion) is a set
of packages that support and implement the SSL and TLS v1 protocols, making those
capabilities available.
BEA WebLogic Server provides Secure Sockets Layer (SSL) support for encrypting data
transmitted between Web Logic Server clients and servers, Java clients, Web browsers,
and other servers. Web Logic Server's Java Secure Socket Extension (JSSE) implementation can
be used by WebLogic clients. Other JSSE implementations can be used for their client-side code
outside the server as well.

The following restrictions apply when using SSL in WebLogic server-side applications:
• The use of third-party JSSE implementations to develop WebLogic server applications
is not upported. The SSL implementation that WebLogic Server uses is static to the server
configuration and is not replaceable by user applications. You cannot plug different JSSE
implementations into WebLogic Server to have it use those implementations for SSL.
• The WebLogic implementation of JSSE does support JCE Cryptographic Service
Providers
(CSPs), however, due to the inconsistent provider support for JCE, BEA cannot guarantee
that

------------------------------------------------------------------------------------------------------------
--------

10 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

untested providers will work out of the box. BEA has tested WebLogic Server with the
following providers:

i) The default JCE provider (SUN JCE Provider) that is included with JDK ii)
The nCipher JCE provider.

SSL can be used on that port. SSL encrypts the data transmitted between the client and
WebLogic Server so that the username and password do not flow in clear text. Java clients use
the Java Naming and Directory Interface (JNDI) to pass on credentials to the WebLogic Server.
A Java client establishes a connection with WebLogic Server by getting a JNDI InitialContext.
The Java client then, uses the InitialContext to look up the resources it needs in the WebLogic
Server JNDI tree.

The following Example demonstrates how to use one-way SSL certificate authentication
in a Java client.
Example of One-Way SSL Authentication Using JNDI:

Hashtable env = new Hashtable();


env.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3s:// weblogic:7002‖);
env.put(Context.SECURITY_PRINCIPAL, "javaclient");
env.put(Context.SECURITY_CREDENTIALS,
"javaclientpassword"); ctx = new InitialContext(env);
(ii) Why do we need inter servlet communication?
(4 marks)

Answer:

Servlets which are running together in the same server have several ways to
communicate with each other. There are three major reasons to use interservlet communication:

a) Direct servlet manipulation / handling


A servlet can gain access to the other currently loaded servlets and perform some task on
each.
The servlet could, for example, periodically ask every servlet to write its state to disk to
protect against server crashes. Direct servlet manipulation / handling involves one servlet
accessing the loaded servlets on its server and optionally performing some task on one or more
of them. A servlet obtains information about other servlets through the ServletContext object.

b) Servlet reuse
Another use for interservlet communication is to allow one servlet to reuse the abilities (the
public methods) of another servlet. The major challenge with servlet reuse is for the ―user‖ servlet to
obtain the proper instance of ―usee‖ servlet when the usee servlet has not yet been loaded into
the server. For example a servlet named as ChatServlet was written as a server for chat applets,
but it could be reused
(unchanged) by another servlet that needed to support an HTML-based chat interface.
Servlet can be done with the user servlet to ask the server to load the usee servlet, then call
getServlet() to get a reference to it.

c) Servlet collaboration

------------------------------------------------------------------------------------------------------------
--------

11 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

Sometimes servlets have to cooperate, usually by sharing some information. We call this
type of communication as servlet collaboration. Collaborating servlets can pass the shared
information directly from one servlet to another through method invocations. This approach
requires each servlet to know the other servlets with which it is collaborating. The most
common situation involves two or more servlets sharing state information. For example, a set of
servlets managing an online store could share
the store's product inventory count. Session tracking can be considered as a special case
of servlet collaboration.

Question 6:

(i) What are the benefits of using Entity beans for database
(6 marks)
operations over directly using JDBC API to do database operation?

Answer:

Entity Beans actually represents the data in a database. It is not that Entity Beans replaces
JDBC
API. There are two types of Entity Beans - Container Managed and Bean Mananged. In a
Container Managed Entity Bean - Whenever, the instance of the bean is created, the
container automatically retrieves the data from the DB/Persistance storage and assigns to the object
variables in the bean for the user to manipulate or use them. For this, the developer needs to map the
fields in the database to the variables in deployment descriptor files (which varies for each vendor).
In the Bean Managed Entity Bean - the developer has to specifically make connection, retrive values,
assign them to the objects in the ejbLoad() which will be called for, by the container when it
instatiates a bean object. Similarly, in the ejbStore() the container saves the object values back to the
persistance storage. ejbLoad and ejbStore are callback methods and can only be
invoked by the container. Apart from this, when you are use Entity beans you do not need to
worry about database transaction handling, database connection pooling etc. which are taken care
of by the ejb
container. But, in case of JDBC you have to explicitly take care of the above features.
The great thing about the entity beans is that container managed is, that, whenever the
connection fail during 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. Whereas in jdbc api, developers need to
maintain the consistency of the database manually.

(ii) Differentiate between JSP and


servelets. (4 marks)

Answer:
SERVLETS
JSP 1. Servlet is
a java class.
1. Jsp is a file.

2. Servlet is a single instance multiple thread web


2. In jsp java code can be included in
application, In which HTML code can be included in
HTML code by using special tags.
java code.

3. In jsp's the presentation logic and B.logic

3. In servlets the presentation logic and the B.logic is


are separated by defining the java beans.
tightly coupled.

------------------------------------------------------------------------------------------------------------
--------

12 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

4. If any modifications done in jsp's


without recompiling and reloading , the
4. For every modification done in servlet program, we
modifications are reflected.

need to recompile and reload the application.

5. In jsp's implicit objects are available

which is we can implement directly into jsp

pages.

5. In servlets implicit objects are not available.

6. Jsp are supported to HTTP protocol

only.

6. Servlets are supported to HTTP, FTP, and SMTP

protocols.
7. No need of Deployment Descriptor file

(web.xml)

7. Sevlets are need Deployment Descriptor file


(web.xml)

Question 7:

(i) The container of EJB provides certain built-in services to EJB,


(6 marks)
which is used by EJB to perform different functions. Define all these functions.

Answer:

The container of EJB provides many built-in functions to EJB, which are as follows:

setEntityContext();

This method is called for, if a container wants to increase its pool size of bean instances,
then, it will instantiate a new entity bean instance. This method associates a bean with context
information. Once this method is called for, then, the bean can access the information
about its environment.

ejbFind(..);

This method is also known as the Finder method. The Finder method locates one or more
existing entity bean data instances in underlying persistent store.

------------------------------------------------------------------------------------------------------------
--------

13 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

ejbHome(..);

The Home methods are special business methods because they are called from a bean in
the pool before the bean is associated with any specific data. The client calls for, home methods
from home interface or local home interface.

ejbCreate();

This method is responsible for creating a new database data and for initialising the bean.

ejbPostCreate();

There must be one ejbPostCreate() for each ejbCreate(). Each method must accept the
same
parameters. The container calls for, ejbPostCreate() right after ejbCreate().
ejbActivate();

When a client calls for, a business method on a EJB object but no entity bean instance is
bound to EJB object, the container needs to take a bean from the pool and transition into a
ready state. This is called Activation. Upon activation the ejbActivate() method is called for by
the ejb container.

ejbLoad();

This method is called for, to load the database in the bean instance.

ejbStore();

This method is used for, to update the database with new values from the memory. This
method is also called for during ejbPassivate().

ejbPassivate();

This method is called for, by the EJB container when an entity bean is moved from
the ready state to the pool state.

ejbRemove();

This method is used to destroy the database data. It does not remove the object. The
object is moved to the pool state for reuse.

unsetEntityContext();

This method removes the bean from its environment. This is called for, just
before destroying the entity bean.

(ii) What criteria should be taken while choosing between


Session (4 marks)
bean and Entity bean?

------------------------------------------------------------------------------------------------------------
--------

14 | P a g e
http://www.IGNOUHelp.in

------------------------------------------------------------------------------------------------------------
---------------------------

Answer:

The following criteria should be taken while choosing between Session bean and Entity
bean:
• A bean developer typically implements a business entity as an entity bean.
• A bean developer typically implements a conversational business process as a stateful
session bean. For example, developers implement the logic of most Web application sessions
as session beans.
• A bean developer typically implements, as an entity bean a collaborative business
process: a business process with multiple actors. The entity object's state represents the
intermediate steps of a business process that consists of multiple steps. For example, an entity
object's state may record the changing information—state—on a loan application as it moves
through the steps of the loan-approval process. The object's state may record that the account
representative entered the information on the loan application, the loan officer reviewed the
application, and application approval is still waiting on a credit report.
• If, it is necessary for any reason to save the intermediate state of a business process in a
database, a bean developer implements the business process as an entity bean. Often, the saved
state itself can be considered a business entity. For example, many e-commerce Web
applications use the concept of a shopping cart, which stores the items that the customer has
selected but not yet checked out. The state of the shopping cart can be considered to be the state
of the customer shopping business process. If, it is desirable that the shopping process span
extended time periods and multiple Web sessions, the bean developer should implement the
shopping cart as an entity bean. In contrast, if the shopping process is limited to a single Web
session, the bean developer can implement the shopping cart as a stateful session bean.

Question 8:

Write a programme using Servelet and JDBC for developing an online


(10 marks)
submission of a telephone bill. You are required to create a database of the
following fields: Telephone no.
Name
Amount
Answer:

Servelet Program: (File name: telebill.java):

import java.io.*;

------------------------------------------------------------------------------------------------------------
--------

15 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

import java.sql.*;

public class telebill extends HttpServlet{

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws IOException, ServletException{

response.setContentType("text/html");

PrintWriter out =

response.getWriter(); try{

String teleno=request.getParameter("teleno");

String name=request.getParameter("name");

String amount=request.getParameter("amount");

Connection connection = null;


try{

Class.forName("oracle.jdbc.driver.OracleDriver");

} catch (ClassNotFoundException e) {

e.printStackTrace();

return;

connection =

DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","lokesh") ;
String insertTableSQL ="INSERT INTO BILL Values(?,?,?)";

PreparedStatement preparedStatement = null;

preparedStatement = connection.prepareStatement(insertTableSQL);

preparedStatement.setString(1,teleno);

preparedStatement.setString(2,name);

------------------------------------------------------------------------------------------------------------
--------

16 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

preparedStatement.setString(3,amount);

int i = preparedStatement.executeUpdate();

if(i!=0) {

out.println("<br>Telephone Bill Submitted Successfully.");

}
else {

out.println("Failed to Submit the bill.");

catch (Exception e) {

out.println(e);

Html Code: (File Name: telebill.html):

<html>

<head><title>Welcome to online Telephone Bill Submission</title></head>

<body>

<form action="servlet/telebill" method="post">

<br>------------------------------------------------------------------------
</br>

<b>------------- Welcome to Online Telephone Bill Submission ------------</b>

<br>------------------------------------------------------------------------
</br>

<p></p>

<table width="274" border="0" cellspacing="1" cellpadding="1">

<tr>

------------------------------------------------------------------------------------------------------------
--------
17 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

<td width="147"><b>Telephone No</b></td>

<td width="120"><input type="text" name="teleno"

size="20"></td> </tr>

<tr>

<td><b>Name</b></td>

<td><input type="text" name="name" size="20"></td>

</tr>

<tr>

<td><b>Amount</b></td>

<td><input type="text" name="amount"

size="20"></td> </tr>

<tr>

<td>&nbsp;</td>

<td align="right"><input type="submit" value="Submit" name="bill"></td>

</tr>

</table>

<p>------------------------------------------------------------------------</p>

<p>------------------------------------------------------------------------</p>

</form>
</body>

</html>

XML Code: (File Name : web.xml):

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

xmlns="http://java.sun.com/xml/ns/javaee"

------------------------------------------------------------------------------------------------------------
--------

18 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<servlet> <servlet-

name>telebill</servlet-name>

<servlet-class>telebill</servlet-class>

</servlet>

<servlet-mapping>
<servlet-name>telebill</servlet-name>

<url-pattern>/servlet/telebill</url-pattern>

</servlet-mapping>

<welcome-file-list> <welcome-

file>telebill.html</welcome-file>

</welcome-file-list>

</web-app>

Output of the above program:

------------------------------------------------------------------------------------------------------------
--------
19 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

Scree shot of compilation of telebill.java file

Scree shot of html page when loaded:


------------------------------------------------------------------------------------------------------------
--------
20 | P a g e
IGNOU MCA 5th Semester July 2013 - January 2014 (MCS-051) Fuly Solved Assignment

------------------------------------------------------------------------------------------------------------
---------------------------

Scree shot of html page after inserting the details before submitting the html form:

Scree shot of html page after submitting the html form:


------------------------------------------------------------------------------------------------------------
--------
21 | P a g e
http://www.IGNOUHelp.in

------------------------------------------------------------------------------------------------------------
---------------------------

Scree shot of database html page before submitting the html form:

Scree shot of database html page after submitting the html form:

For more IGNOU Solved Assignments visit – www.IGNOUHelp.in

Get Daily Updates by Facebook:

https://www.facebook.com/IGNOUHelp.in

You might also like