Simple guide to setup SSL in Tomcat

Author posted by Jitendra on Posted on under category Categories JAVA, JSP, Servlet and tagged as Tags , , with 1 Comment on Simple guide to setup SSL in Tomcat

I have enabled SSL in tomcat many times however initially I struggled to get it in running condition. So I thought to share a simple approach I am following now days.

Step 1:

Run tool “Keytool“ provided by the JRE to create a “keystore file”.
The command to run tool is:

keytool -genkey -alias tomcat -keyalg RSA -keystore D:/.keyStore

Where “D:/.keystore” is the path where file should be created.
Instead of alias “tomcat” any other name can be used.
After running above command, you will be asked many questions, so answer them correctly as shown in below image:

Tomcat SSL keytool to create keystore file
Tomcat SSL keytool to create keystore file

Remember the password provided, as it will be needed in next step. Continue reading “Simple guide to setup SSL in Tomcat”

J2EE – Servlet , JSP , JSF and JMS Version Table

Author posted by Jitendra on Posted on under category Categories JSP, Servlet and tagged as Tags with 1 Comment on J2EE – Servlet , JSP , JSF and JMS Version Table

J2EE – Servlet , JSP , JSF and JMS Version Table

Hi Friends,

Below table gives the information about the versions of J2EE (Java Table Version).

 
J2EE 1.2
JEE 5
Servlet2.22.32.42.5 new3 new
JSP1.11.22.0 new2.12.2
JSTL--1.11.21.2
Tomcat4.x5.x5.x6.x7.x
JMS1.0.21.0.21.11.11.1
JSF---1.22.0 new
J2EE Release DateDec 12, 1999Sep 24, 2001Nov 11, 2003May 11 , 2006Dec 2009
EJB1.12.02.13.03.0
Extra Info----JDK 5 and above required

Create Servlet using Annotation – Servlet 3.0

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with Leave a comment on Create Servlet using Annotation – Servlet 3.0

Create the Servlet without any deployment descriptor. Using Annotations

Before reading this article, i will suggest readers to go through the version table of J2EE.

One of the most appraised feature of Servlet 3.0 is the support of the annotations to create the Servlet. Before  this the Deployment Descriptor (web.xml) was used to create the servlet mapping , defining init parameters etc. All the settings can be now achieved without any entry in web.xml.

Prerequisite:

  1. JDK 5.0 and above.
  2. Tomcat 7
  3. Eclipse 3.6 – Helios (as of now, it only supports Tomcat 7)

We will start with creating the Servlet class : Continue reading “Create Servlet using Annotation – Servlet 3.0”

Step by Step DWR Application – Simple AJAX in JAVA

Author posted by Jitendra on Posted on under category Categories JSP, Servlet and tagged as Tags , , with 18 Comments on Step by Step DWR Application – Simple AJAX in JAVA

Step by Step DWR Application – Simple AJAX in JAVA

In this article, i am going to explain the step by step approach to create the DWR (Direct Web Remoting) application in JAVA.

DWR consists of two main parts:

  • A Java Servlet running on the server that processes requests and sends responses back to the browser.
  • JavaScript running in the browser that sends requests and can dynamically update the webpage.
How DWR works in Java
How DWR works in Java

Continue reading “Step by Step DWR Application – Simple AJAX in JAVA”

Servlet, Hibernate, jQuery and Ajax based google like chat

Servlet, Hibernate, jQuery and Ajax based google like chat with source code

Hi, In this article, my aim is to create an application which uses the concept of Hibernate in Servlet with Ajax support of Jquery.
Below figure can give you the idea of final look and feel of the complete application:

Servlet, Hibernate, jQuery and Ajax based google like chat
Servlet, Hibernate, jQuery and Ajax based google like chat

Continue reading “Servlet, Hibernate, jQuery and Ajax based google like chat”

Read File Present inside Java and J2EE Project

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with Leave a comment on Read File Present inside Java and J2EE Project

How to Read File Present inside Java and J2EE Project

Read File Present inside Java and J2EE Project
Read File Present inside Java and J2EE Project

Consider above project hierarchy, we want to read the file “hibernate.cfg.xml” in “TestMain.java”. If we try to get the absolute path using “(new File(“”)).getAbsolutePath()“ then it will give the path of eclipse in case we are using eclipse or tomcat from where the application is running. This problem occurs mainly in file upload functionality.
Below code can be used to solve this type of problem. Continue reading “Read File Present inside Java and J2EE Project”

Difference in SendRedirect() and RequestDispatcher() in Servlet

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on Difference in SendRedirect() and RequestDispatcher() in Servlet

difference in SendRedirect() and RequestDispatcher() in Servlet

SendRedirect

  • This is the method of object HttpServlerResponse.
  • Request is redirected to client (Browser), and it will process the new URL.
  • End User can see on which page, url is redirected.
  • In Nutshell, Processing done at client side.

RequestDispatcher

  • This object can be accessed from HttpServletRequest.
  • Servlet will internally forward the request to another servlet or jsp page.
  • End user don’t know that which page is processed internally.
  • In Nutshell, Processing done at server side.

Life Cycle of Servlet

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on Life Cycle of Servlet

Explain Life Cycle of Servlet

Servlet is used in J2EE to create the dynamic web pages under Java Environment.  Like Applets, Servlet also have init() and destroy() methods. In this article i will explain the Life cycle of servlet.

Step 1 : After Compilation of the Servlet, the class file is loaded by the loader.

Step 2 : Then the Container instantiates the Servlet class by calling default Constructor. Read this article to know more that how container works for Servlet.

Servlet Life Cycle
Servlet Life Cycle

Continue reading “Life Cycle of Servlet”

How container handles the Servlet request

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 4 Comments on How container handles the Servlet request

How container handles the Servlet request or How the apache Tomcat works

1. User clicks a link that has a URL of Servlet.

Client Browse Servlet URL
Client Browse Servlet URL

Continue reading “How container handles the Servlet request”

Example to Override the init() method of the servlet

Author posted by Jitendra on Posted on under category Categories Servlet and tagged as Tags with 1 Comment on Example to Override the init() method of the servlet

Example to Override the init() method of the servlet

It is not recommended to override the init() method of the servlet.

Here is an example to override init() method of servlet:

    public class BookDBServlet ... {

        private BookstoreDB books;

        public void init(ServletConfig config) throws ServletException {

            // Store the ServletConfig object and log the initialization
            super.init(config);

            // Load the database to prepare for requests
            books = new BookstoreDB();
        }
        ...
    }

you must write super.init(config) code and after that program specific logic.