Pages

Wednesday, May 8, 2013


Advantages of hibernates:
·         Hibernate supports InheritanceAssociationsCollections
·         In hibernate if we save the derived class object,  then its base class object will also be stored into the database, it means hibernate supporting inheritance
·         Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One
·         This will also supports collections like List,Set,Map (Only new collections)
·         In jdbc all exceptions are checked exceptions, so we must write code in try, catch and throws, but in hibernate we only have Un-checked exceptions, so no need to write try, catch, or no need to write throws.  Actually in hibernate we have the translator which converts checked to Un-checked 
·         Hibernate has capability to generate primary keys automatically while we are storing the records into database
·         Hibernate has its own query language, i.e hibernate query language which is database independent
·         So if we change the database, then also our application will works as HQL is database independent
·         HQL contains database independent commands
·         While we are inserting any record, if we don’t have any particular table in the database, JDBC will rises an error like “View not exist”, and throws exception, but in case of hibernate, if it not found any table in the database this will create the table for us ;)
·         Hibernate supports caching mechanism by this, the number of round trips between an application and the database will be reduced, by using this caching technique an application performance will be increased automatically.
·         Hibernate supports annotations, apart from XML
·         Hibernate provided Dialect classes, so we no need to write sql queries in hibernate, instead we use the methods provided by that API.
·         Getting pagination in hibernate is quite simple.



Benefits of Using Spring Framework

·         Spring is Lightweight container
·         No App Server Dependent – like EJB JNDI Calls
·         Objects are created Lazily , Singleton - configuration
·         Components can added Declaratively
·         Initialization of properties is easy – no need to read from properties file
·         Declarative transaction, security and logging service – AOP


Unchecked 
·         ArrayIndexOutOfBoundsException
·         ClassCastException 
·         IllegalArgumentException 
·         IllegalStateException 
·         NullPointerException 
·         NumberFormatException 
·         AssertionError 
·         ExceptionInInitializerError 
·         StackOverflowError 
·         NoClassDefFoundError 

Checked 
·         Exception 
·         IOException 
·         FileNotFoundException 
·         ParseException 
·         ClassNotFoundException 
·         CloneNotSupportedException
·         InstantiationException 
·         InterruptedException
·         NoSuchMethodException
·         NoSuchFieldException












AJAX
AJAX = Asynchronous JavaScript and XML
AJAX is a technique for creating fast and dynamic web pages.
AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.

AJAX










xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();
Method
Description
open(method,url,async)
Specifies the type of request, the URL, and if the request should be handled asynchronously or not.

method: the type of request: GET or POST
url: the location of the file on the server
async: true (asynchronous) or false (synchronous)
send(string)
Sends the request off to the server.

string: Only used for POST requests


Method
Description
setRequestHeader(header,value)
Adds HTTP headers to the request.

header: specifies the header name
value: specifies the header value

Property
Description
responseText
get the response data as a string
responseXML
get the response data as XML data

Property
Description
onreadystatechange
Stores a function (or the name of a function) to be called automatically each time the readyState property changes
readyState
Holds the status of the XMLHttpRequest. Changes from 0 to 4:
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
status
200: "OK"
404: Page not found


Let us see the component and functional differences between struts 1.x and struts 2.x
  •  In struts 1.x front controller is ActionServlet
    • In 2.x front controller is FilterDispatcher
  • In struts 1.x we have RequestProcessor class
    • In 2.x we have Interceptors instead RequestProcessor will see about this concept later just remember as of now
  • In struts 1.x we have multiple tag libraries like, html, logic, bean..etc
    • In 2.x we do not have multiple libraries, instead we have single library which includes all tags
  • In struts 1.x the configuration fine name can be [any name].xml and we used to place in web-inf folder
    • In 2.x the configuration file must be struts.xml only and this must be in classes folder
  • In struts 1.x we have form beans and Action classes separately
    • In 2.x form bean, Action classes are combinedly given as Action class only, of course we can take separately if we want
  • In struts 1.x properties file must be configured in struts-config.xml
    • But in 2.x we need to configure our resource bundle(s) in struts.properties file
  • In struts 1.x we have programmatic and declarative validations only
    • In 2.x we have annotations support too along with programmatic and declarative validations
Functional Differences
  • In struts 1.x declarative validations are done by using validation frame work
    • In 2.x, declarative validations are done by using xwork2 frame work by webwork the reason being, its support valuations through Annotations
  • In struts 1.x an Action class is a single ton class, so Action class object is not a thread safe, as a programmer we need to make it as thread safe by applying synchronization
    • In 2.x an Action class object will be created for each request, so it is by default thread safe, so we no need to take care about safety issues here
  • In struts 1.x we have only jsp as a view technology
    • In 2.x we have support of multiple view technologies like velocity, Freemarker, jasper reports, jsp bla bla
  • In struts 1.x Action class is having servlet dependency, because in execute() method accepts req, res parameter right ! so.
    • In 2.x Action class doesn’t have any servlet dependency, because its execute() method doesn’t accepts any parameters, however we can access all servlet objects with dependency injection

Struts Execution Flow Diagram, How Struts Works




Execution flow of struts

  • When a client request is given, a web container will receive request
  • Web container loads web.xml and verifies whether the url-patterns are verified or not, if matches web-container transfer the request to FilterDispatcher
  • FilterDispatcher hand overs the request to ActionProxy, it is a proxy class which is responsible to apply before and after services to original business logic
  • ActionProxy contacts ConfiguraionManager class, to know the suitable Action for the request and the needed services for the request
  • ConfigurationManager class loads structs.xml and provides the required information back to ActionProxy
  • ActionPorxy delegates the request along with its information to ActionInvocation
  • ActionInvocation executes the interceptors added to an Action from 1 – N, after that it will calls the business logic implemented from N – 1 in reverse order
  • ActionInvocation receives finally result produced by an action aclass
  • ActionProxy transfers the result back to FilterDispatcher
  • FilterDispatcher selects an appropriate view, basing on the result
  • Finally FilterDispatcher uses RequestDispatchers forwarding mechanism and forward a view as a response back to the client





jsp life cycle


traslation
compilation
class loading
instantiation
jsp_init
_jso_service
jsp_destroy



diff b/w jsp include and forward



<%@ %>
page include taglib



useBean
setproperty
getProperty
forward
include

element
attribute
body
text

declaration
directive.include
directive.page
expression
scriplet



fallback
param
plugin



request response

session application

page pageContext

out config exception



request page session application
auto wiring:


no
byName
bytype
constructor
servlets


Interface RequestDispatcher
Interface Servlet
Interface ServletConfig
Interface ServletContext
Interface ServletRequest
Interface ServletResponse
Interface HttpServletRequest
Interface HttpServletResponse
Interface HttpSession

abstract class GenericServlet
abstract class HttpServlet
abstract class ServletInputStream
abstract class ServletOutputStream
abstract class PageContext


class ServletException
Class UnavailableException
Class Cookie








autodirect












Class Action
class ActionServlet
Class ActionErrors
class ActionForward
class ActionMapping
class ActionMessage
class DynaActionForm
class RequestProcessor
class ForwardAction
class IncludeAction
class MappingDispatchAction
class SwitchAction
class EventDispatchAction
class ActionConfig
class ValidatorForm





abstract class ActionForm
abstract class DispatchAction
abstract class LookupDispatchAction

final class LocaleAction

interface Action


class ActionSupport
class FilterDispatcherinterface Action


class ActionSupport
class FilterDispatcher


interface Action
Interface ActionEventListener
Interface ActionProxy
Interface DispatcherListener


Class ActionContext
Class XWork
Class RequestMap
Class SessionMap

Class Action
class ActionServlet
Class ActionErrors
class ActionForward
class ActionMapping
class ActionMessage
class DynaActionForm
class RequestProcessor
Class ActionDispatcher
class ForwardAction
class IncludeAction
class MappingDispatchAction
class SwitchAction
class EventDispatchAction
class ActionConfig
class ValidatorForm
Class DynaValidatorActionForm
class ResponseUtils
Class ValidatorPlugIn
Class Resources
Class DynaValidatorForm

abstract class ActionForm
abstract class DispatchAction
abstract class LookupDispatchAction

final class LocaleAction


servlets


Interface RequestDispatcher
Interface Servlet
Interface ServletConfig
Interface ServletContext
Interface ServletRequest
Interface ServletResponse
Interface HttpServletRequest
Interface HttpServletResponse
Interface HttpSession

abstract class GenericServlet
abstract class HttpServlet
abstract class ServletInputStream
abstract class ServletOutputStream
abstract class PageContext


class ServletException
Class UnavailableException
Class Cookie



auto wiring:


no
byName
bytype
constructor
autodirect


struts-config
->form-beans
->global-exceptions
->global-forwards
->action-mappings
->controller
->message-resources
->plugin

context
->Context
->Resource
tiles-defs
->tiles-definitions
->definition
validation
validation-rules


projectname -> web -> web-inf -> web.xml
     -> struts-config.xml
  -> meta-int-> context.xml
  -> jsp pages
  -> src  -> java    -> java classes, servlets
  -> dist -> war file
actions package

dispatch
forward
include
lookupdispatch
switch


tld files in taglib tag
ex: <%@taglib  uri="/WEB-INF/struts-html.tld" prefix="h" %>

types:

/WEB-INF/struts-html.tld
/WEB-INF/struts-beans.tld
/WEB-INF/struts-logic.tld
/WEB-INF/struts-tiles.tld
/WEB-INF/struts-nested.tld


<%@ %> page,include,taglib
<%! %>
<%-- --%>
<% %>
<%= %>





















request, response,page,pagecontext
session,application,out,config,exception

cookies,hiddenformfields,httpsession,urlrewriting