mcs-051 solved assignment july-jan 2013-14.pdf

Upload: akshay-bhairu-khamkar

Post on 14-Apr-2018

241 views

Category:

Documents


3 download

TRANSCRIPT

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    1/22

    1|P ag ewww.ignousolvedassignments.com

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

    Course Code : MCS-051Course Title : Advanced Internet TechnologiesAssignment Number : MCA (5)/051/Assign/2013Maximum Marks : 100

    Weightage : 25%Last Dates for Submission : 15th October, 2013 (For July 2013 Session)

    15th April, 2014 (For January 2014 Session)

    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);

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

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    2/22

    2|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    preparedStatement.setString(2,"Moisturizer");preparedStatement.setInt(3,45);

    preparedStatement.setString(4,"Ayur Herbal Limited");

    preparedStatement.executeUpdate();System.out.println("\n Record inserted sucessfylly.");

    preparedStatement.close();}

    catch (SQLException s)

    {System.out.println("\n 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("\n Product-ID:\t" + i + "\n Product-name:\t" +n + "\n Price:\t\t" + p + "\n Vender-name:\t" + v);

    }

    connection.close();st.close();res.close();

    }catch (SQLException s){System.out.println("\n SQL code does not execute.");}

    } catch (SQLException e) {

    e.printStackTrace();

    return;}

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

    }}

    }

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    3/22

    3|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    Output of the above program:

    Question 2:

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

    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:

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    4/22

    4|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    5/22

    5|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    (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

    Object state

    Object sharing

    State externalisation

    Transactions

    Session Bean

    Maintained by the container inthe main memory acrosstransactions. Swapped to

    secondary storage whendeactivated.

    A session object can be usedby only one client.

    The container internally

    maintains the session object'sstate. The state is inaccessibleto other programs.

    The state of a session object

    Entity Bean

    Maintained in the database orother resource manager.Typically cached in the

    memory in a transaction.

    An entity object can be sharedby multiple clients. A client

    may pass an object reference toanother client.

    The entity object's state is

    typically stored in a database.Other programs, such as anSQL query, can access thestate in the database.

    The state of an entity object is

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    6/22

    6|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    can be synchronised with a typically changedtransaction but is not transactionally and isrecoverable. recoverable.

    Failure recovery A session object is not

    guaranteed to survive failureand restart of its container. The

    references to session objectsheld by a client becomesinvalid after the failure.

    An entity object survives the

    failure and the restart of itscontainer. A client can

    continue using the referencesto the entity objects after thecontainer 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 toauthenticate the user. As a part of the request, the web server passes the realm (a string) in whichthe 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 clientobtains 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 secureauthentication as user passwords are sent in simple base64 ENCODING (not ENCRYPTED !),

    and there is no provision for target server authentication. Additional protection mechanism can beapplied to mitigate these concerns: a secure transport mechanism (HTTPS), or security at thenetwork 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 ona 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 base64encoding used by Basic Authentication, e.g., HTTPS Client Authentication. As DigestAuthentication is not currently in widespread use, servlet containers are encouraged but NOTREQUIRED to support it.

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    7/22

    7|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    c) Form Based Authentication:

    The look and feel of thelogin screen' cannot be varied using the web browser's built inauthentication 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, therequested web resource is activated and a reference to it is returned. If the user is notauthenticated, all of the following steps occur:

    1) The login form associated with the security constraint is sent to the client and the URL pathtriggering 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 thestatus 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 anauthorised 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. FormBased Authentication has the same lack of security as Basic Authentication since the userpassword 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 somedeployment scenarios.

    Form based login and URL based session tracking can be problematic to implement. Form basedlogin 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 areuseful 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 orFORM 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 dataencryption, server authentication, message integrity, and optional client authentication for a CP/IPconnection. You can think of a public key certificate as the digital equivalent of a passport. It isissued 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 willauthenticate the client using the client's X.509 certificate, a public key certificate that conforms toa standard that is defined by X.509 Public Key Infrastructure (PKI). Prior to running an

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    8/22

    8|P ag ewww.ignousolvedassignments.com

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

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

    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 anXML document by combining XML document and DTD (if any present). Figure below shows asimple relationship between XML documents, DTDs, parsers and applications. XML parser is thesoftware that reads XML files and makes the information from those files available to applicationsand 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 manyXML parsers we shall discuss only Microsoft's parser used by the Internet explorer and W3C'sparser that AMAYA uses.

    XML

    Document

    XML DTD

    (Optional

    )

    XML

    Parser

    XML

    Application

    (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 cryptographicprotocols 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 theclient 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 thereal sender is. A common example is sending a spam e-mail from an address belonging tosomeone else.

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

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    9/22

    9|P ag e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully 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 thoseinvolving 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 byboth parties.

    The pseudo random function splits the input data in 2 halves and processes them with differenthashing 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 datatransmitted 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 theserver 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 notupported. 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 intoWebLogic 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

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    10/22

    10 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

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

    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 WebLogicServer so that the username and password do not flow in clear text. Java clients use the JavaNaming and Directory Interface (JNDI) to pass on credentials to the WebLogic Server. A Javaclient 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 JNDItree.

    The following Example demonstrates how to use one-way SSL certificate authentication in a Javaclient.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 witheach 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 protectagainst server crashes. Direct servlet manipulation / handling involves one servlet accessing theloaded 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 publicmethods) of another servlet. The major challenge with servlet reuse is for the user servlet toobtain the proper instance of usee servlet when the usee servlet has not yet been loaded into theserver. For example a servlet named as ChatServlet was written as a server for chat applets, but itcould be reused

    (unchanged) by another servlet that needed to support an HTML-based chat interface. Servlet canbe 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

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    11/22

    11 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    Sometimes servlets have to cooperate, usually by sharing some information. We call this type ofcommunication as servlet collaboration. Collaborating servlets can pass the shared information

    directly from one servlet to another through method invocations. This approach requires eachservlet 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 managingan online store could share

    the store's product inventory count. Session tracking can be considered as a special case of servletcollaboration.

    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 JDBCAPI. There are two types of Entity Beans - Container Managed and Bean Mananged. In aContainer Managed Entity Bean - Whenever, the instance of the bean is created, the containerautomatically 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 inthe database to the variables in deployment descriptor files (which varies for each vendor). Inthe 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 itinstatiates a bean object. Similarly, in the ejbStore() the container saves the object values back tothe 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 ejbcontainer. But, in case of JDBC you have to explicitly take care of the above features. The greatthing about the entity beans is that container managed is, that, whenever the connection fail duringtransaction processing, the database consistancy is mantained automatically. The container writesthe data stored at persistant storage of the entity beans to the database again to provide thedatabase 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 JSP1. Servlet is

    a java class. 1. Jsp is a file.

    2. Servlet is a single instance multiple thread web

    application, In which HTML code can be included in

    java code.

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

    tightly coupled.

    2. In jsp java code can be included in

    HTML code by using special tags.

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

    are separated by defining the java beans.

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    12/22

    12 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    4. If any modifications done in jsp's

    without recompiling and reloading , the

    4. For every modification done in servlet program, we

    need to recompile and reload the application.

    5. In servlets implicit objects are not available.

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

    protocols.

    7. Sevlets are need Deployment Descriptor file

    (web.xml)

    modifications are reflected.

    5. In jsp's implicit objects are available

    which is we can implement directly into jsp

    pages.

    6. Jsp are supported to HTTP protocol

    only.

    7. No need of 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, itwill instantiate a new entity bean instance. This method associates a bean with contextinformation. 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 existingentity bean data instances in underlying persistent store.

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    13/22

    13 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    ejbHome(..);

    The Home methods are special business methods because they are called from a bean in the poolbefore 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 sameparameters. 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 toEJB object, the container needs to take a bean from the pool and transition into a ready state. This iscalled 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 isalso 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?

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    14/22

    14 | P a g ehttp://www.ignousolvedassignments.com

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

    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 sessionbean. For example, developers implement the logic of most Web application sessions as sessionbeans.

    A bean developer typically implements, as an entity bean a collaborative business process: abusiness process with multiple actors. The entity object's state represents the intermediate steps ofa business process that consists of multiple steps. For example, an entity object's state may recordthe changing informationstateon 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 theinformation 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 itselfcan be considered a business entity. For example, many e-commerce Web applications use theconcept 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 customershopping business process. If, it is desirable that the shopping process span extended time periodsand 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 developercan 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.*;

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

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    15/22

    15 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully 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);

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    16/22

    16 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    preparedStatement.setString(3,amount);

    int i = preparedStatement.executeUpdate();

    if(i!=0) {

    out.println("
    Telephone Bill Submitted Successfully.");

    }

    else {

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

    }

    }

    catch (Exception e) {

    out.println(e);

    }

    }

    }

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

    Welcome to online Telephone Bill Submission


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

    -------------Welcome to Online Telephone Bill Submission------------


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

    --------------------------------------------------------------------------------------------------------------------By: Mr. Lokesh Chandra Singh. (09334255802)

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    17/22

    17 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    Telephone No

    Name

    Amount

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

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

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    18/22

    18 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully 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">

    telebill

    telebill

    telebill

    /servlet/telebill

    telebill.html

    Output of the above program:

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    19/22

    19 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully Solved Assignment

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

    Scree shot of compilation of telebill.java file

    Scree shot of html page when loaded:

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    20/22

    20 | P a g e

    IGNOU MCA 5thSemester July 2013 - January 2014 (MCS-051) Fully 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:

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

  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    21/22

    21 | P a g ehttp://www.ignousolvedassignments.com

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

    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 Please Visit -www.ignousolvedassignments.com

    Connect on Facebook :http://www.facebook.com/pages/IgnouSolvedAssignmentscom/346544145433550

    http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/http://www.ignousolvedassignments.com/
  • 7/27/2019 MCS-051 Solved Assignment July-Jan 2013-14.pdf

    22/22

    Subscribe and Get Solved Assignments Direct to your Inbox :http://feedburner.google.com/fb/a/mailverify?uri=ignousolvedassignments_com