Thursday, 9 October 2014

Spring MVC Flow Diagram



1.      Whenever end user given the request then Spring MVC front controller called Dispatch Servlet will receive the request.
2.      Then Dispatcher Servlet communicate with the HandlerMapping for identifying the suitable controller for given request.
3.      After identifying the suitable controller for the given request HandlerMapping returns the information back to the Dispatcher Servlet.
4 & 5.      Then Dispatcher Servlet dispatches the given request to the controller bean. Controller bean stores the given input in a command class object.
6.      Controller bean calls the business logic implemented in a model.
7 ,8 &9 .      The model can integrate with database and reads or update data.
         Model component returns result back to controller bean.
10.      Controller bean returns model and view object back to Dispatcher Servlet.
11.      Dispatcher servlet communicate the with the view resolver bean and this bean identifies      appropriate view for the given model and view object.
12.  Dispatcher servlet selects the view identified by the view resolver.
            Dispatcher Servlet either forward or redirects the view as a response back to the client.

How to maintain the Session in Servlet?

Session Tracking in Servlets

Session simply means a particular interval of time.
Session Tracking is a way to maintain state (data) of an user. It is also known as session management in servlet.
Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.
HTTP is stateless that means each request is considered as the new request. It is shown in the figure given below:
There are four techniques used in Session tracking:
  1. Cookies
  2. Hidden Form Field
  3. URL Rewriting
  4. HttpSession
session tracking

Wednesday, 8 October 2014

Dimond program in Java

import java.util.Scanner;
public class StarDimond {

public static void main(String[] args)
    {
        System.out.print("Enter no of row u want in star pattern : ");
        Scanner in = new Scanner(System.in);
                int num=in.nextInt();
                for(int i=1;i<=num;i++)
                {
                    for(int j=num;j>=i;j--)
                    {
                        System.out.print(" ");
                    }
                   for(int m=1;m<=i;m++)
                    {
                       System.out.print(" *");
                    }
                     System.out.print("\n");
                }
                for(int i=1;i<=num;i++)
                {
                    for(int j=1;j<=i;j++)
                    {
                        System.out.print(" ");
                    }
                   for(int m=num;m>=i;m--)
                    {
                       System.out.print(" *");
                    }
                     System.out.print("\n");
                }  
    }
}
 
Out put:Enter no of row u want in star pattern : 5
      *
     * *
    * * *
   * * * *
  * * * * *
  * * * * *
   * * * *
    * * *
     * *
      *


Wednesday, 1 October 2014

What Session.refresh() method will do in hibernate

Session.refresh() method :  During the bulk update to the DB with hibernate, the changes made are not replicated to the entities stored in the current session. So calling session.refresh will load the modifications to session entities.