পৃষ্ঠাসমূহ

Search Your Article

CS

Pageviews

Showing posts with label Basic JSP Tutorial. Show all posts
Showing posts with label Basic JSP Tutorial. Show all posts

Saturday, January 21, 2017

JSP - Overview

What is JavaServer Pages?

JavaServer Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>.

JSP - Environment Setup

A development environment is where you would develop your JSP programs, test them and finally run them.
This tutorial will guide you to setup your JSP development environment which involves following steps:

JSP - Architecture

The web server needs a JSP engine ie. container to process JSP pages. The JSP container is responsible for intercepting requests for JSP pages. This tutorial makes use of Apache which has built-in JSP container to support JSP pages development.

JSP - Life Cycle

The key to understanding the low-level functionality of JSP is to understand the simple life cycle they follow.
A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
The following are the paths followed by a JSP

JSP - Syntax

This tutorial will give basic idea on simple syntax (ie. elements) involved with JSP development:

The Scriptlet:

A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language.

JSP - Directives

JSP directives provide directions and instructions to the container, telling it how to handle certain aspects of JSP processing.

JSP - Actions

JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.

JSP - Implicit Objects

JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer can call them directly without being explicitly declared. JSP Implicit Objects are also called pre-defined variables.
JSP supports nine Implicit Objects which are listed below:

JSP - Client Request

When a browser requests for a web page, it sends lot of information to the web server which can not be read directly because this information travel as a part of header of HTTP request. You can check HTTP Protocol for more information on this.

JSP - Server Response

When a Web server responds to a HTTP request to the browser, the response typically consists of a status line, some response headers, a blank line, and the document. A typical response looks like this:
HTTP/1.1 200 OK
Content-Type: text/html

JSP - Http Status Codes

The format of the HTTP request and HTTP response messages are similar and will have following structure:
  • An initial status line + CRLF ( Carriage Return + Line Feed ie. New Line )
  • Zero or more header lines + CRLF
  • A blank line ie. a CRLF

JSP - Form Processing

You must have come across many situations when you need to pass some information from your browser to web server and ultimately to your backend program. The browser uses two methods to pass this information to web server. These methods are GET Method and POST Method.

JSP - Filters

Servlet and JSP Filters are Java classes that can be used in Servlet and JSP Programming for the following purposes:
  • To intercept requests from a client before they access a resource at back end.
  • To manipulate responses from server before they are sent back to the client.

JSP - Cookies Handling

Cookies are text files stored on the client computer and they are kept for various information tracking purpose. JSP transparently supports HTTP cookies using underlying servlet technology.
There are three steps involved in identifying returning users:

JSP - Session Tracking

HTTP is a "stateless" protocol which means each time a client retrieves a Web page, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.
Still there are following three ways to maintain session between web client and web server:

JSP - File Uploading

A JSP can be used with an HTML form tag to allow users to upload files to the server. An uploaded file could be a text file or binary or image file or any document.

JSP - Handling Date

One of the most important advantages of using JSP is that you can use all the methods available in core Java. This tutorial would take you through Java provided Date class which is available in java.util package, this class encapsulates the current date and time.

JSP - Page Redirecting

Page redirection is generally used when a document moves to a new location and we need to send the client to this new location or may be because of load balancing, or for simple randomization.

JSP - Hits Counter

A hit counter tells you about the number of visits on a particular page of your web site. Usually you attach a hit counter with your index.jsp page assuming people first land on your home page.
To implement a hit counter you can make use of Application Implicit object and associated methods getAttribute() and setAttribute().

JSP - Auto Refresh

Consider a webpage which is displaying live game score or stock market status or currency exchange ration. For all such type of pages, you would need to refresh your web page regularly using refresh or reload button with your browser.