Skip to main content


Showing posts from December, 2010

Ajax with jsp : simple example

HTML Page < html >      < head > < title > welcome </ title >      < script   language = "javascript" >         reqObj=null;         function  varify (){             document. getElementById ("res").innerHTML=" Checking ";              if (window.XMLHttpRequest){                 reqObj=new  XMLHttpRequest ();             }else {                 reqObj=new  ActiveXObject ("Microsoft.XMLHTTP");             }                          reqObj.onreadystatechange=process;             reqObj. open ("POST","./a.jsp?id="+document. getElementById ("username").value,true);             reqObj. send (null);         }         function  process (){              if (reqObj.readyState== 4 ){                 document. getElementById ("res").innerHTML=reqObj.responseText;             }         }          </ script >           </ head >      < body >     

Diffrences between forward and sendRedirect, MCS-051, June 2009, 5a(i)

forward() sendRedirect() it is used to invoke another server from one servlet with is same server it can send request to page on another server It forward the same request and response object from one servlet to another servlet. It does not send request and response object to another servlet. Redirection occures within server. it sends response code to client side application to send the request to another serlver or resoures. this method is availabe through RequestDispatcher Object. This is method of response object. It transfer control to another servlet for further processing It send response to browser and then browser agian sends request for second servlet or resource Data submitted to first servlet will be availble for second servlet. Data of first servlet is not availble for secind servlet.

Diffrences between Servlet config and servlet context, MCS-051, June 2009, 5a(i)

Servlet context Servlet config It is an Object to be shared by all servlets and JSPs. this object is associated to specific servlet unlimited store of data as per as server capability limited support for data handling can be used to collaboration between multiple servlet. It is for single servlet Data stored here can be access from any servlet and JSP Data stored here can be access from the servlet for which this object is associated It is created using getServletContext() method of Servlet class Created using getServletConfig() method Only Single instance available within web application Multiple instances for each servlet. contains global properties like classpath, context path etc Only contains property related to specific servlet.

Differences between Session and cookie, MCS-051, June-2008-4b

Session Cookie Data on server-side data on client side unlimited side of data as per as server capability limited support for data data handling It can store any type of data only text age of data is not fixed . fixed destroy after session timeout or logout remains on client machine less data traveling over the network All cookie need to travel each time client sends request to server. More secure mechanism to session tracking less secure

Using SSL in java program

import*; import; import*; import*; public class SSLTest { public static voi d main(String[] args) throws Exception { String https_url = " " ; URL url; url = new URL(https_url); HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); if (con != null ) { System.out.println( " Response Code : " + con.getResponseCode()); System.out.println( " Cipher Suite : " + con.getCipherSuite()); System.out.println( " \n " ); Certificate[] certs = con.getServerCertificates(); int i=0; for (Certificate cert : certs) { System.out.println( " Cert NO : " +i++); System.out.println( " Cert Type : " + cert.getType()); System.out.printl

Write a program to create a XML document from a telephone directory database. Dec08_4a

import java.sql.*; public class Dec08_4a { public static void main(String ar[])throws Exception { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=database.mdb"); //Connection con = DriverManager.getConnection("jdbc:odbc:mydsn"); Statement st = con.createStatement(); ResultSet rs = st.executeQuery("select * from phoneDirectory"); System.out.println("<phone-directory>"); while ( { System.out.println(" <customer>"); String s1 = rs.getString(1); System.out.println(" <customer-name>"+s1+"</customer-name>"); String s2 = rs.getString(2); System.out.println(" <address>"+s2+"</address>"); String s3 = rs.getString(3); System.out.println(" <phone-number>"

Write a code for servlet which will display all the fields of Employee table in tabular form.MCS-051,Dec09-3a

import javax.servlet.*; import*; import java.sql.*;   import javax.servlet.http.*;   public class Employee extends HttpServlet   {   public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException,      ServletException   {   res.setContentType("text/Html");   PrintWriter pw = res.getWriter();   try   {   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   Connection con=DriverManager.getConnection("jdbc:odbc:dsn");   Statement st=con.createStatement();   ResultSet rs=st.executeQuery("select emp_id,emp_name,emp_dob,mob_no,email from employee");   String tr="";   while({   tr=tr+"<tr>";   tr=tr+"<td>"+rs.getString(1)+"</td>";   tr=tr+"<td>"+rs.getString(2)+"</td>";   tr=tr+"<td>"+rs.getString(3)+"</td>";   tr=tr+"<td>"+rs.getString(4)+"</td>&

Web application for student registration, where student can register online with enrollment number. ther registered students should be able to log on after getting registered. you are required to use JSP, servlet, and JDBC. . MCS-051, Dec2009-1b.

StudentRegistration │ index.html │ login.html │ └───WEB-INF │ web.xml │ └───classes login.class regform.class Index.html <html> <head> <title>registration</title> </head> <body> <form method="post" action="reg"> NAME:<input type="text"name="t1"/><br> ENROLLMENT:<input type="text"name="t2"/><br> PASSWORD:<input type="password"name="t3"/><br> <input type="submit"value="send"/><br> </form> <a href='login.html'>if already registered plz login</a> </body> </html> login.html <html> <head> <title>login</title> </head> <body> <form method="post" action="login"> <h2>ENTER VALID USER NAME AND PASSWORD</h

Write a code in JSP to insert a record in product table with fields: prod_d id, prod_name, quantity, price. Assuming that product table is create in MS-Access database. MCS51-june09-1b

JSP code <%@page import="java.sql.*"%> <%! int prod_id=1; String prod_name="Laptop"; int qty=2; float price=22000.30f; %> <% try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:NaveenRahul"); Statement st=con.createStatement(); String query="insert into product values("+prod_id+",'"+prod_name+"',"+qty+","+price+")"; if(st.executeUpdate(query)>0){ out.write("Records inserted"); }else{ out.write("insertion faild"); } }catch(Exception e){ out.write("Exception : "+e); } %> JAVA Codes import java.sql.*; class Insert2{ public static void main(String ar[]){ int prod_id=2; String prod_name="Laptop"; int qty=2; float price=22000.30f; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection(&q

Compare and contrast, SSL and TLS, MCS51-dec2007-1(g)

SSL TLS SSL stands for Secure Sockets Layer. TLS stands for Transport Layer Security. Netscape originally developed this protocol. The Internet Engineering Task Force (IETF) created TLS as the successor to SSL.TLS as the successor to SSL. SSL works mainly through using public/private key encryption on data. TLS uses stronger encryption algorithms and has the ability to work on different ports It is commonly used on web browsers It is most often used as a setting in email programs SSL connections begin with security and proceed directly to secured communications TLS connections first begin with an insecure “hello” to the server and only switch to secured communications after the handshake between the client and the server is successful

Example of Message Driven Bean, MCS51-june2007-3(ii)

Simple example for the MDB without configuration file.  package  mdb; import  javax.ejb. * ; import  javax.jms. * ; import  javax.naming. * ; public   class MyMDB implements  MessageDrivenBean, MessageListener {    public MyMDB ()    {    } // invoked first after ejbCreate() of MDB    public   void   setMessageDrivenContext ( MessageDrivenContext mdc )    {    } // invoked first after just object creation of MDB    public   void   ejbCreate ()    {      System .out. println ( "ejbCreate(): "   +   this ) ;    } // this method is invoked when any message arrives on the destination for which this MDB has been configured.     public   void   onMessage ( Message inMessage )    {      try      {        System .out. println ( "Message received: "   +  inMessage ) ;      }   catch   ( Exception  e )      {       e. printStackTrace () ;      }    } // this method invoked when MDB object being destroyed by EJB server    public   v

MCs-051, June2007,1(iv), Three type of entities

Internal Entities : If entities stored in declaration tag within same document, it is called internal entity. for example <!ENTITY BCA "Bachelor of Computer Application" > It is internal entity and we can use it as &bca; anywhere in the document. When XML parser process these entities, it replaces them to their corresponding values.   External Entities : Entities those point external source of contents like pointing external xml file are referred as External entities. for example; <ENTITY course SYSTEM "/location/course.xml"> this entity is pointing external document course.xml. where XML parser interpret this entity, contents of course.xml document are inserted at the location of entity.   Parameter Entities. Parameter are entites those are used to hold the DTD's declarations as a parameters. Using parameter entities (prefixed with a %), a type entity can be created. Then this entity can replace the parameter list. The % type; entity

MCA - June, 2007 - 1(i)

Write a servlet program that takes your name and address from an HTML form and display it. Application index.html WEB-INF web.xml classes web.xml <web-app> <servlet> <servlet-name>Display</servlet-name> <servlet-class>Display</servlet-class> </servlet> <servlet-mapping> <servlet-name>Display</servlet-name> <url-pattern>/Display</url-pattern> </servlet-mapping> </web-app> import*; import javax.servlet.*; import javax.servlet.http.*; public class Display extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter pw=response.getWriter(); String name=request.getParameter("name"); String address=request.getParameter(&qu