Like This Site? 
 
RSS Feed Follow Us 

on Twitter! Be Our Fan!

JSP, Servlets and Java Web Services

Share this post!
 Vote this!

As a Unix administrator you can avoid supporting much of the applications that run on your servers and contain yourself with just the Unix aspects, but as I personally feel the Unix admin role itself is diminishing (no networking, less volume manager stuff, etc) you have to obtain additional skills, my thoughts are that you need to start to look after some of the applications that run on a Unix server i.e. Java EE Application Servers (Apache/Tomcat, JBoss AS 5, etc) and how they work in the bigger picture, its still kind of admin work and the script programming has been replaced with HTML, JSP and Java.                   more...

Counting Active Users using JSP

Share this post!
 Vote this!

Ever wondered how many users are viewing your web site at this moment? well this article seems to answer that. We will learn how to count active users using one session listener class and a JSP page. Once you have read this article, you'll be able to see the number of active sessions on your web site. This is all fun, so keep reading.  

What is a Session ?
A session is a sort of temporary unique connection between the server and client ( browser ) by which the server keeps track of that specific user. That unique session can be used by web applications to display this content to one user and that content to the other user.  more...

JSP Standard Tag Library (JSTL) Tutorial

Share this post!
 Vote this!

The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications.
JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags.
The JSTL tags can be classified, according to their functions, into following JSTL tag library groups that can be used when creating a JSP page:
  1. Core Tags
  2. Formatting tags
  3. SQL tags
  4. XML tags
  5. JSTL Functions  more...

JSP : Controlling HTTP Response Header Lines

Share this post!
 Vote this!

HTTP Response Syntax
Based on HTTP/1.1 protocol, after receiving and interpreting an HTTP request from a client, a server must responds with an HTTP response following the syntax bellow:
status-line
header-line
...
header-line

entity-body
Note that:
  • Response must have one status-line.
  • Response can have zero, one, or many header lines.
  • Response can only have zero or one entity-body.
  • There is a blank line between header lines and the entity body.
  • Status line, head line, and blank line must be ended with CRLF ("/r/n") characters.
  • Entity body is the actual data requested by the client request.
  • Header lines can be in any order.  more...

Servlets Advanced Features

Share this post!
 Vote this!

After describing some basic programming of servlets, we will describe some advanced topics of servlets in this tutorial, viz., Session Tracking, Servlet Filters, Servlet Life Cycle Events, Including, forwarding and redirecting, Servlet Chaining and Applet Servlet Communication.

Session Tracking

HTTP is a stateless protocol which means that each request done using HTTP is independent from each other. This is a restriction in HTTP since some applications like e-commerce sites require to hold state information. One of the traditional examples of state is a shopping cart. In this tutorial, we will learn how to hold states between HTTP requests using servlets.  more...

JSP - Sending Email

Share this post!
 Vote this!

To send an email using a JSP is simple enough but to start with you should have JavaMail API and Java Activation Framework (JAF) installed on your machine.
  • You can download latest version of JavaMail (Version 1.2) from Java's standard website.
  • You can download latest version of JavaBeans Activation Framework JAF (Version 1.0.2) from Java's standard website.
Download and unzip these files, in the newly created top level directories you will find a number of jar files for both the applications. You need to add mail.jar and activation.jar files in your CLASSPATH.

Send a Simple Email:

Here is an example to send a simple email from your machine. Here it is assumed that your localhost is connected to the internet and capable enough to send an email. Same time make sure all the jar files from Java Email API package and JAF package ara available in CLASSPATH.  more...

JSP : Auto Refresh

Share this post!
 Vote this!

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 referesh or reload button with your browser.
JSP makes this job easy by providing you a mechanism where you can make a webpage in such a way that it would refresh automatically after a given interval.
The simplest way of refreshing a web page is using method setIntHeader() of response object. Following is the signature of this method:
public void setIntHeader(String header, int headerValue)
This method sends back header "Refresh" to the browser along with an integer value which indicates time interval in seconds.  more...

JSP : Page Redirecting

Share this post!
 Vote this!

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.
The simplest way of redirecting a request to another page is using method sendRedirect() of response object. Following is the signature of this method:
public void response.sendRedirect(String location)
throws IOException 
This method sends back the response to the browser along with the status code and new page location. You can also use setStatus() and setHeader() methods together to achieve the same redirection:
....
String site = "http://www.newpage.com" ;
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site); 
.... more...

JSP - File Uploading

Share this post!
 Vote this!

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.

Creating a File Upload Form:

The following HTM code below creates an uploader form. Following are the important points to be noted down:
  • The form method attribute should be set to POST method and GET method can not be used.
  • The form enctype attribute should be set to multipart/form-data.
  • The form action attribute should be set to a JSP file which would handle file uploading at backend server. Following example is using uploadFile.jsp program file to upload file.
  • To upload a single file you should use a single <input .../> tag with attribute type="file". To allow multiple files uploading, include more than one input tags with different values for the name attribute. The browser associates a Browse button with each of them.  more...

JSP : Cookies Handling

Share this post!
 Vote this!

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:
  • Server script sends a set of cookies to the browser. For example name, age, or identification number etc.
  • Browser stores this information on local machine for future use.
  • When next time browser sends any request to web server then it sends those cookies information to the server and server uses that information to identify the user or may be for some other purpose as well.
This chapter will teach you how to set or reset cookies, how to access them and how to delete them using JSP programs.  more...

JSP - Filters : Complete Tutorial

Share this post!
 Vote this!

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.
There are are various types of filters suggested by the specifications:
  • Authentication Filters.
  • Data compression Filters
  • Encryption Filters .
  • Filters that trigger resource access events.
  • Image Conversion Filters .
  • Logging and Auditing Filters.
  • MIME-TYPE Chain Filters.
  • Tokenizing Filters .
  • XSL/T Filters That Transform XML Content.  more...

JSP : MVC Tutorial

Share this post!
 Vote this!

This is a simple Model View Controller (MVC) tutorial, although this is a very small application it uses the MVC model approach which proves that even small applications can use MVC. The following is what we will be doing in this tutorial,
  • Writing an HTML form page
  • Creating a Servlet controller - Controller
  • Creating the Model (a plain old Java class) - Model
  • Creating an XML deployment descriptor
  • Creating an JSP View - View
You will need the following requirements already setup, you can use either Unix/Linux or Windows the choice is yours

JSP : Web Application Architecture

Share this post!
 Vote this!

When a request comes in something has to to instantiate the servlet or at least make a new thread to handle the request. Something has to call the servlets doPost() or doGet() method and they have crucial arguments - the HTTP request and HTTP response objects, so something has to handle the life, death and resources of the servlet and that something is the Web Container.
What is a Container
Tomcat is an example of a container, when a web server gets a request for a servlet , the web server hands the request to the Container in which the servlet is deployed. It's the Container that gives the servlet the HTTP request and response and it's the Container that calls the servlet's methods (doPost() and getGet()).  more...

Filters and Wrappers : Complete Tutorial

Share this post!
 Vote this!

Filters can intercept the request and also control the response all without the servlet knowing, which means that filters can be used without touching the servlets code, filters can be a very powerful tool.
Filters are Java components (very similar to servlets) that you can use to intercept and process requests before that are sent to the servlet, or to process responses after the servlet has completed, but before the response goes back to the client. The Container decides when to invoke your filters based on the declarations in the DD, the DD maps which filters will be called for which request URL patterns.
The are many things that you can do with filters
  • perform security checks (request)
  • reformat request headers or bodies (request)
  • audit or log requests (request)
  • compress the response stream (response), I have an example of this below
  • append or alter the response stream (response)
  • create a different response altogether (response)  more...

JSP - Filters

Share this post!
 Vote this!

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.
There are are various types of filters suggested by the specifications:
  • Authentication Filters.
  • Data compression Filters
  • Encryption Filters .
  • Filters that trigger resource access events.
  • Image Conversion Filters .
  • Logging and Auditing Filters.
  • MIME-TYPE Chain Filters.
  • Tokenizing Filters .
  • XSL/T Filters That Transform XML Content.  more...

JSP Http Status Codes : Complete Tutorial

Share this post!
 Vote this!

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
  • An optioanl message body like file, query data or query output.
For example, a server response header looks as follows:
HTTP/1.1 200 OK
Content-Type: text/html
Header2: ...
...
HeaderN: ...
  (Blank Line)
<!doctype ...>
<html>
<head>...</head>
<body>
...
</body>
</html>
The status line consists of the HTTP version (HTTP/1.1 in the example), a status code (200 in the example), and a very short message corresponding to the status code (OK in the example).  more...

Implement JavaScript with JSP

Share this post!
 Vote this!

In this section we are going to implement  insert data, delete data, and update data using with JDBC database and also using of JavaScript.
Step 1: Create employee form (EmployeeInformation.jsp) .
In this step first of all create Employee information form and retrieved employee id from database using with JDBC database.  
Here is the  code EmployeeInformation.jsp  more...

JSP - Server Response

Share this post!
 Vote this!

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
Header2: ...
...
HeaderN: ...
  (Blank Line)
<!doctype ...>
<html>
<head>...</head>
<body>
...
</body>
</html>   more...

JSP : Reading Request Information

Share this post!
 Vote this!

Reading Request Information Reading Request Information When an HTTP client such as web browser sends a request to a wen server, along with the request it also sends some HTTP variables like Remote address, Remote host, Content type etc. In some

Reading Request Information

When an HTTP client such as web browser sends a request to a wen server, along with the request it also sends some HTTP variables like Remote address, Remote host, Content type etc. In some cases these variables are useful to the programmers. So here is the code of the jsp file which prints the HTTP request information:  more...

Accessing database from JSP

Share this post!
 Vote this!

This article explains the connectivity from MYSQL database with JSP.we take a example of Books database. This database contains a table named books_details. This table contains three fields- id, book_name& author. we starts from very beginning. First we learn how to create tables in MySQl database after that we write a html page for inserting the values in 'books_details' table in database. After submitting values a table will be showed that contains the book name and author name.
Database

The database in example consists of a single table of three columns or fields. The database name is "books" and it contains information about books names & authors. more...