World's most popular travel blog for travel bloggers.
Showing posts with label MCS051. Show all posts
Showing posts with label MCS051. Show all posts
00:00:00



Xml for a medical store

Create a servlet to print schedule of mcsl-054

The questions in test should be of multiple choice type  and true/ false type. There should be provisions for registration,  examination and to see the results after examination. Use  servlet,jsp,jdbc, to develop this application. Makenecessary  assumptions require. 
00:00:00

Backup and Recovery Procedures

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


Disaster recovery (DR) security issues pop up frequently in the IT industry. Storage managers often cover the basic security measures in their environment, but that's often not enough; data security issues must be addressed in IT disaster recovery plans. Also, storage managers should always look at data security from the perspective of a malicious attacker. With these two strategies, companies can better recover their systems if they're attacked and/or go down.

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


The most critical file is the Security File itself. CA Top Secret has an automatic backup feature that is set to copy the Security File to a DASD backup file daily, at 1:00 a.m. by default. This Backup File is critical to the built-in recovery capability. You can change the time of backup or deactivate the automatic backup through the BACKUP control option. Also, a backup can be taken at any time from the console using the BACKUP control option. In a shared environment, a backup is only active on one system

CA Top Secret also includes a recovery mechanism based on the DASD backup and the Recovery File. This procedure is implemented and tested before serious security maintenance begins so that all Security File updates can be recovered. We recommend using backup and recovery procedures to protect your CA Top Secret Security File. These procedures were designed for quick, accurate, and dependable recovery.

Operator Training

When setting up the backup and recovery procedures, you may also take time to train key operations personnel in the use of the backup and recovery routines so that they are prepared to execute them when necessary. Emergencies do not present the appropriate opportunity for training.


Candidates for Offsite Storage

As with all critical files used in your installation, all of the following CA Top Secret files must be backed up to tape daily, and may be candidates for offsite storage:


  • Security File
  • Security File backup
  • Recovery File
  • Audit/Tracking File
  • Parameter File

Offsite storage protects these files if your data center experiences a major disaster.

We recommend that the Security File reside on a different volume and string than that of the Backup and Recovery Files. This allows you to use the Backup and Recovery Files to quickly and easily circumvent minor hardware problems that affect access to the Security File.

Entity Bean Features

An entity bean represents a business object in a persistent storage mechanism. Some examples of business objects are customers, orders, and products. In the J2EE SDK, the persistent storage mechanism is a relational database. Typically, each entity bean has an underlying table in a relational database, and each instance of the bean corresponds to a row in that table.

Important Features of Entity Beans

These are the key features of entity beans:
  • Persistence—Entity bean persistence can be managed by the EJB container, or the bean itself. If a bean uses container-managed persistence, the EJB container automatically generates the necessary database access calls. The code that you write for the entity bean does not include these calls. With bean-managed persistence, you must write the database access code and include it in the bean.
  • Shared Access—Throughout its lifecycle, an entity bean instance can support multiple clients, although not at the same time. Because the clients might want to change the same data, it is important that entity beans work within transactions. Typically, the EJB container provides transaction management. In this case, you specify the transaction attributes in the bean's ejb-jar.xml file that control how transactions are managed. You do not have to code the transaction boundaries in the bean—the container marks the boundaries for you. For information about transaction management, see Features and Design Patterns.
  • Primary Key—Each entity bean has a unique object identifier. A customer entity bean, for example, might be identified by a customer number. The unique identifier, or primary key, enables the client to locate a particular entity bean. For more information, see Using Container-Managed Relationships (CMRs).
  • Relationships—Like a table in a relational database, an entity bean may be related to other entity beans. You implement relationships differently for entity beans with bean-managed persistence and for those with container-managed persistence. With bean-managed persistence, the code that you write implements the relationships. But with container-managed persistence, the EJB container takes care of the relationships for you. For this reason, relationships in entity beans with container-managed persistence are often referred to as container-managed relationships. For more information, see Using Cascade Delete for Entities in CMRs.

Difference Between Bean-Managed and Container-Managed Beans


There are two methods for managing the persistent data within an entity bean: bean-managed and container-managed persistence. The main difference between bean-managed and container-managed persistent beans is defined by who manages the persistence of the entity bean's data.

In practical terms, the following table provides a definition for both types and a summary of the programmatic and declarative differences between them:

Bean-Managed Persistence  Container-Managed Persistence  

Persistence management  

You are required to implement the persistence management within the ejbStore and ejbLoad EntityBean methods. These methods must contain logic for saving and restoring the persistent data.
For example, the ejbStore method must have logic in it to store the entity bean's data to the appropriate database. If it does not, the data can be lost. See "3. Implementing EntityBean Interface Methods" for an example of implementing bean-managed persistence.  

The management of the persistent data is done for you. That is, the container invokes a persistence manager on behalf of your bean.
You use ejbStore and ejbLoad for preparing the data before the commit or for manipulating the data after it is refreshed from the database. The container always invokes the ejbStore method right before the commit. In addition, it always invokes the ejbLoad method right after reinstating CMP data from the database.  

Finder methods allowed  

The findByPrimaryKey method and any other finder method you wish to implement are allowed.  

Only the findByPrimaryKey method and a finder method for the where clause are allowed.  

Defining CMP fields  

N/A  

Required within the EJB deployment descriptor. The primary key must also be declared as a CMP field.  

Mapping CMP fields to resource destination.  

N/A  

Required. Dependent on persistence manager.  

Definition of persistence manager.  

N/A  

Required within the Oracle-specific deployment descriptor. See the next section for a description of a persistence manager.  

Callback Methods in EntityBean

Callback Method  Functionality Required  

ejbCreate  

The same functionality as bean-managed persistent beans. You must initialize all container-managed persistent fields, including the primary key.  

ejbPostCreate  

The same functionality as bean-managed persistent beans. You have the option to provide any other initialization, which can involve the entity context.  

ejbRemove  

No functionality for removing the persistent data from the outside resource is required. The persistent manager removes all persistent data associated with the entity bean from the database. You must at least provide an empty implementation for the callback, which means that you can add logic for performing any cleanup functionality you require.  

ejbFindByPrimaryKey 

No functionality is required for returning the primary key to the container. The container manages the primary key--after it is initialized by the ejbCreate method. Thus, the container performs the functionality normally required of this method. You still must provide an empty implementation for this method.  

ejbStore  

No functionaltiy is required for saving persistent data within this method. The persistent manager saves all persistent data to the database for you. However, you must provide at least an empty implementation as the container invokes the ejbStore method before invoking the persistent manager. This enables you to perform any data management or cleanup before the persistent data is saved.  

ejbLoad  

No functionality is required for restoring persistent data within this method. The persistence manager restores all persistent data for you. However, you must provide at least an empty implementation as the container invokes the ejbLoad method after invoking the persistent manager. This enables you to perform any logic to manipulate the persistent data after it is restored to the bean.  

setEntityContext  

Associates the bean instance with context information. The container calls this method after the bean creation. The enterprise bean can store the reference to the context object in an instance variable, for use in transaction management. Beans that manage their own transactions can use the session context to get the transaction context.
You can also allocate any resources that will exist for the lifetime of the bean within this method. You should release these resources in unsetEntityContext.  

unsetEntityContext 

Unset the associated entity context and release any resources allocated in setEntityContext.  

SSL Client Application Components 

At a minimum, an SSL client application comprises the following components: 

Java client 

A Java client performs these functions:

  • Initialises an SSLContextwith client identity, a HostnameVerifierJSSE, a TrustManagerJSSE, and a HandshakeCompletedListener. 
  • Creates a keystore and retrieves the private key and certificate chain. 
  • Uses an SSLSocketFactory, and 
  • Uses HTTPS connect to a JSP served by an instance of WebLogic

HostnameVerifier


The HostnameVerifier implements the weblogic.security.SSL.HostnameVerifierJSSE interface. It provides a callback mechanism so that implementers of this interface can supply a policy for handling the case where the host that is being connected the server name from the c(SubjectDN) must match. 

HandshakeCompletedListener 

The HandshakeCompletedListener implements the javax.net.ssl.HandshakeCompletedListenerinterface. It defines how the SSL client receives notifications about the completion of an SSL handshake on a given SSL connection. It also defines the number od times an SSL handshake takes place on a given SSL connection. 

TrustManager

The TrustManager implements the weblogic.security.SSL.TrustManagerJSSE interface. it builts a certificate path to a trusted root and returns true if it can be validated and is trusted for client SSL authentication.

build script (build.xml)

This script compiles all the files required for the application and deploys them to the WebLogic Server applications directories.

Sample package code for this type program


package examples.security.sslclient;

import java.io.File;
import java.net.URL;
import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Hashtable;
import java.security.Provider;
import javax.naming.NamingException;
import javax.naming.Context;
import javax.naming.InitialContext
import javax.servlet.ServletOutputStream;
import weblogic.net.http.*;
import weblogic.jndi.Environment;
/** SSLClient is a short example of how to use the SSL library o
* WebLogic to make outgoi
* d
* WebLogic (in a Servlet).
*
*/

>> See complete program in STUDY MATERIAL MCS051 Block 3 Page 37

Differences between Session and cookie, MCS-051

SessionCookie
Data on server-sidedata on client side
unlimited side of data as per as server capabilitylimited support for data data handling
It can store any type of dataonly text
age of data is not fixed .fixed
destroy after session timeout or logoutremains on client machine
less data traveling over the networkAll cookie need to travel each time client sends request to server.
More secure mechanism to session trackingless secure


For 4 Marks above chart is enough, Find below the detail for understanding the concept of both

A cookie is simply a short text string that is sent back and forth between the client and the server. You could store name=bob&password=asdf in a cookie and send that back and forth to identify the client on the server side. You could think of this as carrying on an exchange with a bank teller who has no short term memory, and needs you to identify yourself for each and every transaction. Of course using a cookie to store this kind information is horrible insecure. Cookies are also limited in size.
Now, when the bank teller knows about his/her memory problem, He/She can write down your information on a piece of paper and assign you a short id number. Then, instead of giving your account number and driver's license for each transaction, you can just say "I'm client 12"
Translating that to Web Servers: The server will store the pertinent information in the session object, and create a session ID which it will send back to the client in a cookie. When the client sends back the cookie, the server can simply look up the session object using the ID. So, if you delete the cookie, the session will be lost.
One other alternative is for the server to use URL rewriting to exchange the session id.
Suppose you had a link - www.myserver.com/myApp.jsp You could go through the page and rewrite every URL as www.myserver.com/myApp.jsp?sessionID=asdf or even www.myserver.com/asdf/myApp.jsp and exchange the identifier that way. This technique is handled by the web application container and is usually turned on by setting the configuration to use cookieless sessions.




Basic Syntax

  1. <jsp:plugin type"applet | bean" code"nameOfClassFile"   
  2. codebase"directoryNameOfClassFile"  
  3. </jsp:plugin>  

index.jsp


<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Mouse Drag</title>
    </head>
    <body bgcolor="khaki">
<h1>Mouse Drag Example</h1>

 <jsp:plugin align="middle" height="500"
     type="applet"  code="MouseDrag.class" name="clock" codebase="."/>

    </body>
</html>  

First Create Table in your Database

create database SampleDB;
 
use SampleDB;
 
CREATE TABLE  product (
     product_id  Number NOT NULL AUTO_INCREMENT,
     productname  varchar(45) NOT NULL,
     Quality number NOT NULL,
     Price decimal NOT NULL,
     model varchar(45) NOT NULL,
 description varchar(245) NOT NULL,
    PRIMARY KEY (product_id)
);


Java Code


//STEP 1. Import required packages
import java.sql.*;

public class JDBCExample {
   // JDBC driver name and database URL
   static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
   static final String DB_URL = "jdbc:oracle://localhost/products";

   //  Database credentials
   static final String USER = "username";
   static final String PASS = "password";
   
   public static void main(String[] args) {
   Connection conn = null;
   Statement stmt = null;
   try{
      //STEP 2: Register JDBC driver
      Class.forName("com.mysql.jdbc.Driver");

      //STEP 3: Open a connection
      System.out.println("Connecting to a selected database...");
      conn = DriverManager.getConnection(DB_URL, USER, PASS);
      System.out.println("Connected database successfully...");
      
      //STEP 4: Execute a query
      System.out.println("Inserting records into the table...");
      stmt = conn.createStatement();
      
      String sql = "INSERT INTO Products " +
                   "VALUES (100, 'Mobile 2', 1, 1800, 's7', 'Its a good pfone')";
      stmt.executeUpdate(sql);
       
      System.out.println("Inserted records into the table...");

   }catch(SQLException se){
      //Handle errors for JDBC
      se.printStackTrace();
   }catch(Exception e){
      //Handle errors for Class.forName
      e.printStackTrace();
   }finally{
      //finally block used to close resources
      try{
         if(stmt!=null)
            conn.close();
      }catch(SQLException se){
      }// do nothing
      try{
         if(conn!=null)
            conn.close();
      }catch(SQLException se){
         se.printStackTrace();
      }//end finally try
   }//end try
   System.out.println("Goodbye!");
}//end main
}//end JDBCExample

SAMPLE CODE (Update according to your Field Names/Requirement)

import javax.servlet.http.*;
import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import javax.xml.parsers.ParserConfigurationException;
        import javax.xml.transform.OutputKeys;
        import javax.xml.transform.Result;
        import javax.xml.transform.Source;
        import javax.xml.transform.Transformer;
        import javax.xml.transform.TransformerConfigurationException;
        import javax.xml.transform.TransformerException;
        import javax.xml.transform.TransformerFactory;
        import javax.xml.transform.dom.DOMSource;
        import javax.xml.transform.stream.StreamResult;
        import org.w3c.dom.Document;
        import org.w3c.dom.Element;
 
   public static void main(String[] args) throws ParserConfigurationException,
   TransformerException {
  DocumentBuilder builder = null;
  try {
   builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  } catch (ParserConfigurationException e) {
   throw e;
  }
  Document document = builder.newDocument();
  // create root element
  Element root = document.createElement("Users");
                // attach it to the document
  document.appendChild(root);
                // create user node
  Element user = document.createElement("User");
                // create its id attribute
  user.setAttribute("id", "2");
                // add user node to root node
  root.appendChild(user);
                // create name node and set its value
  Element userName = document.createElement("name");
  userName.setTextContent("codippa");
                // attach this node to user node
  user.appendChild(userName);
                // write xml
  Transformer transformer;
  try {
   TransformerFactory transformerFactory = TransformerFactory
     .newInstance();
   transformer = transformerFactory.newTransformer();
   Result output = new StreamResult(new File("codippa.xml"));
   Source input = new DOMSource(document);
                        // if you want xml to be properly formatted
   transformer.setOutputProperty(OutputKeys.INDENT, "yes");
   transformer.transform(input, output);
  } catch (TransformerConfigurationException e) {
   throw e;
  } catch (TransformerException e) {
   throw e;
  }
 }

Steps to Fetch Student Data from Database

Create Html Page


index.html

<!DOCTYPE html>
<html>
    <head>
        <title>TODO supply a title</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="viewport" content="width=device-width">
    </head>
    <body>
       <form action="Search">
Enter your Name: <input type="text" name="uname"/><br/>
<input type="submit" value="search"/>
</form>
    </body>
</html>





Create Java Servlet

Search.java


import java.io.*;

import java.sql.*;

import javax.servlet.ServletException;
import javax.servlet.http.*;
public class Search extends HttpServlet {
       public void doGet(HttpServletRequest request, HttpServletResponse response)
                     throws ServletException, IOException {
              response.setContentType("text/html");
              PrintWriter out = response.getWriter();        
              String name=request.getParameter("uname");                          
              try{
                     Class.forName("oracle.jdbc.driver.OracleDriver");
                     Connection con=DriverManager.getConnection("jdbc:oracle:thin:@mcndesktop07:1521:xe","sandeep","welcome");               
                     PreparedStatement ps=con.prepareStatement("select * from userlogin where name=?");
                     ps.setString(1,name);                   
                     out.print("<table width=25% border=1>");
                     out.print("<center><h1>Result:</h1></center>");
                     ResultSet rs=ps.executeQuery();                
                     /* Printing column names */
                     ResultSetMetaData rsmd=rs.getMetaData();
                     while(rs.next())
                        {
                     out.print("<tr>");
                     out.print("<td>"+rsmd.getColumnName(1)+"</td>");
                        out.print("<td>"+rs.getString(1)+"</td></tr>");
                        out.print("<tr><td>"+rsmd.getColumnName(2)+"</td>");
                        out.print("<td>"+rs.getString(2)+"</td></tr>");
                        out.print("<tr><td>"+rsmd.getColumnName(3)+"</td>");
                        out.print("<td>"+rs.getString(3)+"</td></tr>");
                        out.print("<tr><td>"+rsmd.getColumnName(4)+"</td>");
                        out.print("<td>"+rs.getString(4)+"</td></tr>");                  
                     }
                     out.print("</table>");

              }catch (Exception e2)
                {
                    e2.printStackTrace();
                }

              finally{out.close();
                }
       }

} 

Compile your servlet code and add to Apache Directory > web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 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_3_0.xsd">
    <servlet>
        <servlet-name>Search</servlet-name>
        <servlet-class>Search</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Search</servlet-name>
        <url-pattern>/Search</url-pattern>
    </servlet-mapping>
</web-app>