World's most popular travel blog for travel bloggers.

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> 



Coming soon

Become a Member to this website http://www.ignougroup.com/register/ and get informed 

1. Difference between stored procedure and function

2. Index types in SQL Server

3. How you will take backup of your database?

4. How many types of memories are there in .net? 

5. Which controls you used in your project?

6. Can you Explain Page lifecycle in .net?

7. Can you Explain .NET architecture in .net?

8. What is the difference between primary key and unique key with not null?

9. What is session? Explain login form.

10. What is 3-tier architecture of .net application?

Operating Systems

Non contiguous memory allocation methodology does require that a file be termed at the start. The file grows as needed with time. A major advantage is the reduced waste of disk space and flexibility when it comes to memory allocation. The Operating System will allocation memory to the file when needed.
Non contiguous memory allocation, offers the following advantages over contiguous memory allocation:
  • Allows the interdependence of code and data among processes.
  • External fragmentation is none existent with non contiguous memory allocation.
  • Virtual memory allocation is strongly supported in non contiguous memory allocation.
Non contiguous memory allocation methods include Paging and Segmentation.

Paging

Paging is a non contiguous memory allocation method in which physical memory is divided into fixed sized blocks called frames of size in the power of 2, ranging from 512 to 8192 bytes. Logical memory is also divided into same size blocks called pages. For a program of size n pages to be executed, n free frames are needed to load the program.
Some of the advantages and disadvantages of paging as noted by Dhotre include the following:
  • On advantages:
  • Paging Eliminates Fragmentation
  • Multiprogramming is supported
  • Overheads that come with compaction during relocation are eliminated
  • Some disadvantages that include:
  • Paging increases the price of computer hardware, as page addresses are mapped to hardware
  • Memory is forced to store variables like page tables
  • Some memory space stays unused when available blocks are not sufficient for address space for jobs to run

Segmentation

Segmentation is a non contiguous memory allocation technique that supports a user view of memory. A program is seen as a collection of segments such as main program, procedures, functions, methods, stack, objects, etc.
Some of the advantages and disadvantages of segmentation as noted by Godse et al include the following:
  • On advantages:
  • Fragmentation is eliminated in Segmentation memory allocation
  • Segmentation fully supports virtual memory
  • Dynamic memory segment growth is fully supported
  • Segmentation supports Dynamic Linking
  • Segmentation allows the user to view memory in a logical sense.

  • On the disadvantages of segmentation:
  • Main memory will always limit the size of segmentation, that is, segmentation is bound by the size limit of memory
  • It is difficult to manage segments on secondary storage
  • Segmentation is slower than paging
  • Segmentation falls victim to external fragmentation even though it eliminates internal fragmentation