Skip to main content

Posts

Showing posts from February 20, 2017

Servlet Life Cycle

Java Servlet Life Cycle A   servlet   is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. For such applications, Java Servlet technology defines HTTP-specific servlet classes. The   javax.servlet   and   javax.servlet.http   packages provide interfaces and classes for writing servlets. All servlets must implement the   Servlet   interface, which defines life-cycle methods. When implementing a generic service, you can use or extend the   GenericServlet   class provided with the Java Servlet API. The   HttpServlet   class provides methods, such as   doGet   and   doPost , for handling HTTP-specific services. Servlet Life Cycle The life cycle of a servlet is controlled by the container in which the servlet has been deployed. When a

What is MVC architecture in J2EE

What is MVC architecture in J2EE MVC stands for Model-View-Controller architecture. It promotes loose coupling between components by separating the functionality of displaying and maintaining of the data. It is often used by applications that need the ability to maintain multiple views like HTML, WML, Swing, XML based Web service etc. Multiple views and controllers can interface with the same model. Even new types of views and controllers can interface with a model without forcing a change in the model design. To summarize the MVC does the following Separation of Model from View components makes it possible to implement several user interfaces that reuse the common core business logic. Duplication of low-level Model code is eliminated across multiple UI implementations. Decoupling of Model and View code results in an improved ability to write unit tests for the core business logic code. Modularity of components allows core logic developers and UI developers to wor

Object Relational Mapping

Object Relational Mapping   ( ORM)  in   computer science   is a   programming   technique for converting data between incompatible   type systems   in   object-oriented   programming languages. In   object-oriented programming,   data-management   tasks act on object-oriented (OO)   objects   that are almost always non-scalar   values. For example, consider an address book entry that represents a single person along with zero or more phone numbers and zero or more addresses. This could be modeled in an object-oriented implementation by a "Person   object" with   attributes/fields   to hold each data item that the entry comprises: the person's name, a list of phone numbers, and a list of addresses. The list of phone numbers would itself contain "PhoneNumber objects" and so on. The address-book entry is treated as a single object by the programming language (it can be referenced by a single variable containing a pointer to the object, for instance).

JSP Lifecycle

JSP Lifecycle The lifecycle of a JSP is the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step, which translates the JSP into a Servlet. Following are the JSP Lifecycle phases. 1.       Translation of JSP to Servlet code. 2.       Compilation of Servlet to bytecode. 3.       Loading Servlet class. 4.       Creating servlet instance. 5.       Initialization by calling jspInit() method 6.       Request Processing by calling _jspService() method 7.       Destroying by calling jspDestroy() method JSP Lifecycle JSP Translation and Compilation When a user request for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine does the following 1.     Parse the JSP 2.     Transforms the JSP to a Servlet 3.     Compile the Servlet (.java) file to a c

What is Bean scope in Spring MVC framework with Example

What is Bean scope in Spring MVC framework with Example Bean scope in Spring framework  or Spring MVC are scope for a bean managed by  Spring IOC container . As we know that Spring is a framework which is based on  Dependency Injection  and  Inversion of Control  and provides bean management facilities to Java application. In Spring managed environment bean (Java Classes) are created and wired by Spring framework. Spring allows you to define how those beans will be created and scope of bean is one of those details. This Spring tutorial is next on my earlier post on Spring like  how to implement LDAP authentication using Spring security  and   How to limit number of user session in web application , if you haven’t read them already you may find them useful.  In spring framework bean declared in  ApplicationContext.xml  can reside in five scopes: 1) Singleton (default scope) 2) prototype 3) request 4) session 5) global-session Singleton  and  prototype  are

Spring 4 - Auto Component scanning example

Spring 4 - Auto Component scanning example Technologies used:    JDK 1.8.0_121 | Spring 4.3.5.RELEASE | Maven 3.9.9 | Eclipse Mars.2 (4.5.2) Spring provides four stereotype annotations:  @Component ,  @Controller ,  @Service  and  @Repository  for spring-managed components. The  @Controller ,  @Service  and  @Repository  annotations are specializations of the  @Component  annotation for more specific purpose in presentation, service and data access layer respectively. In Spring framework, we can enable the auto component scanning by using The  <context:component-scan/>  element in XML based configuration The  @ComponentScan  annotation in java based configuration The  AnnotationConfigApplicationContext#scan()  method Create Spring Components Create an  EmployeeService  bean under  com.boraji.tutorial.spring.service  package as follows. EmployeeService.java package com.boraji.tutorial.spring.service; import org.springframework.beans.f