From Twitter

PREDEFINED VARIABLES

PREDEFINED VARIABLES

 To simplify code in JSP expressions and scriptlets, Servlet also creates several objects
to be used by the JSP engine; these are sometimes called implicit objects (or

JSP DECLARATIONS

JSP DECLARATIONS

JSP Syntax: <%! code %>
XML Syntax: <jsp:declaration> code </jsp:declaration>
 

JSP SCRIPLETS

JSP SCRIPLETS

JSP Syntax: <% code %>
XML Syntax: <jsp: scriptlet > code </jsp:scriptlet>
 

JSP EXPRESSIONS

JSP EXPRESSIONS

JSP Syntax: <%= code %>
XML Syntax: <jsp:expression > code </jsp:expression>

SCRIPTING ELEMENTS

SCRIPTING ELEMENTS

Now, after going through the basic concepts of JSP, we will understand different types
of tags or scripting elements used in JSP.

RELATION OF APPLETS AND SERVLETS WITH JSP

RELATION OF APPLETS AND SERVLETS WITH JSP

Now, in this topic we shall compare applets, servlets and JSP and shall try to make a
relationship among these.
 

JAVA SERVER PAGES-I OVERVIEW OF JSP

 JAVA SERVER PAGES-I OVERVIEW OF JSP

As you have already studied in previous units, servlets offer several improvements
over other server extension methods, but still suffer from a lack of presentation a

SOLUTIONS / ANSWERS

SOLUTIONS / ANSWERS

1) True or False

a) True

b) True

2) JDBC is a standard SQL database access interface that provides uniform access
to a wide range of relational databases. It also provides a common base on

USING JDBC TO MODIFY A DATABASE

USING JDBC TO MODIFY A DATABASE

Modifying a database is just as simple as querying a database. However, instead of
using executeQuery(), you use executeUpdate() and you don’t have to worry about a

USING JDBC TO QUERY A DATABASE

USING JDBC TO QUERY A DATABASE

Let us take an example to understand how to query or modify a database. Consider a
table named as CUSTOMER is created in MS-ACCESS, with fields cust_id, name,

STEPS TO CONNECT TO A DATABASE

STEPS TO CONNECT TO A DATABASE

Now, we shall learn step-by-step process to connect a database using Java. The
interface and classes of the JDBC API are present inside the package called as java.sql
 

TYPES OF JDBC DRIVERS

TYPES OF JDBC DRIVERS

We have learnt about JDBC API. Now we will study different types of drivers
available in java of which some are pure and some are impure.

JDBC API

Now, we will learn about the JDBC API. The JDBC API is implemented through the
JDBC driver. The JDBC Driver is a set of classes that implement the JDBC interfaces

HOW DOES JDBC WORK?

HOW DOES JDBC WORK?


Simply, JDBC makes it possible to do the following things within a Java application: :
 
• Establish a connection with a data source
• Send SQL queries and update statements to the data source
• Process the results at the front-end
Figure 1 shows the components of the JDBC model



ab
abab

 The Java application calls JDBC classes and interfaces to submit SQL statements and
retrieve results.

JAVA DATABASE CONNECTIVITY JDBC Vs. ODBC

JAVA DATABASE CONNECTIVITY JDBC Vs. ODBC


Now, we shall study the comparison between JDBC and ODBC. The most widely
used interface to access relational databases today is Micorsoft’s ODBC API. ODBC

SOLUTIONS/ANSWERS

SOLUTIONS/ANSWERS

  1) True/ False
 
a) False b) True c) True
 
2) A servlet is a Java class and therefore needs to be executed in a Java VM by a
service we call a Servlet engine. Servlets dynamically extend the functionality
of a web server and basically developed for the server side applications. Servlets
have the following advantages over other common server extension
mechanisms:

 • They are faster than other server extensions like, CGI scripts because they
use a different process model.
• They use a standard API that is supported by many web servers.
• It executes within the address space of a web server.
• Since servlets are written in Java, servlets are portable between servers and
operating systems. They have all of the advantages of the Java language,
including ease of development and platform independence.
• It does not require creation of a separate process for each client request

 3) Code to display “Welcome to Fifth semester of MCA”
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");

 out.println("<HEAD><TITLE>5th Semester MCA </TITLE></HEAD>");
out.println("<BODY>");
out.println("<B>Welcome to Fifth Semester of MCA</B>");
out.println("</BODY></HTML>");
}
}

 4) Servlets are the Java classes which are created when needed and destroyed
when not needed. Since servlets run within a Servlet Container, creation and
destruction of servlets is the duty of Servlet Container. There are three principal
stages in the life of a Java Servlet Life Cycle, namely:
 
i) Servlet Initialisation: In this first stage, the servlet's constructor is called
together with the servlet method init( ) - this is called automatically once
during the servlet's execution life cycle and can be used to place any one-off
initialisation such as opening a connection to a database.
 
ii) Servlet Execution: Once your servlet is initialized and its init() method
called, any request that the Servlet Container receives will be forwarded to
your Servlet's service() method. HttpServlet class breaks this service() method
into more useful doGet(), doPost(), doDelete(), doOptions(), doPut() and
doTrace() methods depending on the type of HTTP request it receives. So in
order to generate response, the doGet() or doPost() method should be
overridden as per the requirement.
 
When a servlet request is made to the Servlet engine, the Servlet engine
receives all the request parameters (such as the IP address of client), user
information and user data and constructs a Servlet request object, which
encapsulates all this information

iii) Servlet Destruction: When the application is stopped or Servlet Container
shuts down, Servlet’s destroy() method will be called to clean up any
resources allocated during initialisation and to shutdown gracefully. Hence, it
acts as a place to deallocate resources such as an open file or open database
connection



INTER-SERVLET COMMUNICATION

INTER-SERVLET COMMUNICATION

Now, we shall study why we need InterServlet communication. 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:

DATABASE CONNECTIVITY WITH SERVLETS

DATABASE CONNECTIVITY WITH SERVLETS

 Now we shall study how we can connect servlet to database. This can be done with
the help of JDBC (Java Database Connectivity). Servlets, with their enduring life
cycle, and JDBC, a well-defined database-independent database connectivity API, are
an elegant and efficient combination and solution for webmasters who require to
connect their web sites to back-end databases

A Hit Count Using Session Tracking

A Hit Count Using Session Tracking

 Let us understand session tracking with a simple servlet to count the number of times
a client has accessed it, as shown in example below. The servlet also displays all the
bindings for the current session, just because it can.

SERVLET SESSION TRACKING

SERVLET SESSION TRACKING

Many web sites today provide custom web pages and / or functionality on a client-byclient
basis. For example, some Web sites allow you to customize their home page to
suit your needs. An excellent example of this the Yahoo! Web site. If you go to the
site http://my.yahoo.com/
You can customize how the Yahoo! Site appears to you in future when you revisit the
website. HTTP is a stateless protocol: it provides no way for a server to recognise that
a sequence of requests is all from the same client. Privacy advocates may consider this
a feature, but it causes problems because many web applications aren’t stateless. The

shopping cart application is another classic example—a client can put items in his Servlet Programming
virtual cart, accumulating them until he checks out several page requests later.
Obviously the server must distinguish between clients so the company can determine
the proper items and charge the proper amount for each client.
Another purpose of customizing on a client-by-client basis is marketing. Companies
often track the pages you visit throughout a site so they display advertisements that
are targeted to user’s browsing needs.
 
To help the server distinguish between clients, each client must identify itself to the
server. There are a number of popular techniques for distinguishing between clients.
In this unit, we introduce one of the techniques called as Session Tracking.
Session tracking is wonderfully elegant. Every user of a site is associated with a
javax.servlet.http.HttpSession object that servlets can use to store or retrieve
information about that user. You can save any set of arbitrary Java objects in a session
object. For example, a user’s session object provides a convenient location for a
servlet to store the user’s shopping cart contents.
A servlet uses its request object’s getSession() method to retrieve the current
HttpSession object:
 
public HttpSession HttpServletRequest.getSession(boolean create)
This method returns the current session associated with the user making the request. If
the user has no current valid session, this method creates one if create is true or returns
null if create is false. To ensure the session is properly maintained, this method must
be called at least once before any output is written to the response.
You can add data to an HttpSession object with the putValue() method:
public void HttpSession.putValue(String name, Object value)

This method binds the specified object value under the specified name. Any existing
binding with the same name is replaced. To retrieve an object from a session, use
 
getValue():
public Object HttpSession.getValue(String name)
This methods returns the object bound under the specified name or null if there is no
binding. You can also get the names of all of the objects bound to a session with
 
getValueNames():
public String[] HttpSession.getValueNames()
This method returns an array that contains the names of all objects bound to this
session or an empty (zero length) array if there are no bindings. Finally, you can
remove an object from a session with removeValue():
 
public void HttpSession.removeValue(String name)
This method removes the object bound to the specified name or does nothing if there
is no binding. Each of these methods can throw a java.lang.IllegalStateException if
the session being accessed is invalid

the servlet API HttpServletRequest and HttpServletResponse

HTTPSERVLETREQUEST INTERFACE

There are two important interfaces included in the servlet API HttpServletRequest and
HttpServletResponse
The interface HttpServletRequest encapsulates the functionality for a request object
that is passed to an HTTP Servlet.

SERVLET LIFE CYCLE with example

SERVLET LIFE CYCLE

After learning the basics of Servlet now, we shall study the life cycle of a Servlet.
Servlets are normal Java classes, which are created when needed and destroyed when
not needed. A Java Servlet has a lifecycle that defines how the Servlet is loaded and
initialized, how it receives and responds to requests, and how it is taken out of service.
In code, the Servlet lifecycle is defined by the javax.servlet.Servlet interface.

YOUR FIRST JAVA SERVLET


  
Servlets are basically developed for server side applications and designed to handle
http requests. The servlet-programming interface (Java Servlet API)
is a standard part of the J2EE platform and has the following advantages over other
common server extension mechanisms:

SERVLET PROGRAMMING HOW TO INSTALL SERVLET ENGINE/WEB

SERVLET PROGRAMMING 
   
We have already know core Java and how to compile and learn the Java
programs.  we shall cover the basics of Java Servlet and different interfaces


of Servlet. Java Servlets are the small, platform-independent

Explain recursion C program Tower of Hanoi of 4 disks



Explain recursion. Also write a C program for Tower of Hanoi problem with
a example of 4 disks 



The C language allows programmer to write functions that calls themselves and this is called Recursion.
                                #include<stdio.h>
                                #include<conio.h>
                                void TOH(int,char,char,char);
                                void main()
                                {
                                                int n;
                                                clrscr();
                                                printf(“Enter the number of disk: “);
                                                scanf(“%d”,&n);
                                                printf(“Tower of  hannoi problem for %d disk: \n”,n);
                                                TOH(‘n’,’A’,’B’,’C’);
                                                getch();
                                }
                                void TOH(int n, char A, char B, char C)
                                {
                                                if(n<=0)
                                                                printf(“\n Wrong input \n”);
                                                else if(n==1)
                                                                printf(“\n Move disk from peg %c to peg %c”,A,C);
                                                else
                                                {
                                                                TOH(n-1,A,C,B);
                                                                TOH(1,A,B,C);
                                                                TOH(n-1,B,A,C);
                                                }
                                }

Labels

(MCS-031 (6) 2011 (5) 4nf (1) 5nf (1) ACCESS CONTROL In Relational Database (1) ALGORITHMICS (5) assignment 2014 2015 (1) AVAILABLE TOOLS & ALGORITHMS (5) BCA (1) BINARY SEARCH (1) Block Nested Loop Join (1) Build and Fix Model (1) BUILDING BLOCKS OF ALGORITHMS (1) CHARACTERISTICS OF AN ALGORITHM (2) Core Java (1) Data Communication Network Security (1) DATABASE SECURITY (1) EER tool (1) ELEMEMTARY ALGORITHMICS (2) ENHANCED ER TOOLS (1) EVOLUTION (1) EXAMPLE OF AN ALGORITHM (2) Indexed Nested-Loop Join (1) install servelet engine (1) INTRODUCTION (1) Iterative Enhancement Model (1) Java Server Pages (1) JDBC (1) JSP (2) LEVELS OF DATABASE SECURITY (1) MCA (9) MCA 051 (1) MCA 3rd Semester (8) MCA 4th Semester (1) MCA 5 sem (1) MCS-031 (7) MCS-031 : DESIGN AND ANALYSIS OF ALGORITHM (14) MCS-032 (1) MCS-033 (1) MCS-034 (2) MCS-035 (1) mcs-041 (2) MCS-042 (1) mcs-043 (2) mcs-052 solved assignment (1) MCSL-036 (2) Nested loop join (1) OBJECTIVES (1) Operating System (2) OUTLINE OF ALGORITHMICS (1) Principles of Management and Information Systems (1) PROBLEMS (1) QUERY PROCESSING AND EVALUATION (1) Query processing Optimisation (1) Question Papers (8) Related Topic (9) relational Database (1) SELECT OPERATION Query Processing (1) Servlet (1) Servlet Programme (1) Servlet Programming (1) SOFTWARE DEVELOPMENT MODELS (4) SOFTWARE ENGINEERING (4) Solution (7) Solved Assignment 2013 2014 (6) SOME PRE-REQUISITES AND Asymptotic Bounds ASYMPTOTIC BOUNDS INTRODUCTION (1) STATISTICAL DATABASE SECURITY (1) structure (1) SUMMARY (1) Waterfall Model (1) Write a C program to print the following triangle (1)