Java J2EE Training Report
May 8, 2017 | Author: mansha99 | Category: N/A
Short Description
training...
Description
A Training Report On J2EE
A Training Report submitted in partial fulfillment of requirements for the degree of Bachelor of Engineering In Computer Science & Engineering PREFACE
This report deals with programming in java and in particular advanced java. Each and every topic is kept in proper sequence with thorough planning. The details of every topic are explained as simply as possible.
We hope that the project will find greater appreciation among different readers and teachers about its usefulness. It would be my sane opportunity to know if any mistakes have crept in to the script.
Acknowledgement I acknowledge my gratitude and thank to all the well knowledge persons for giving me opportunity to avail all the best facilities available at this networking institute through which I have gained knowledge thinking so as too just in the environment suitable for harmonic adjustment. I am grateful to the following person for various
help rendered by them during my vocational training period.
Last but not the least; I thank my teacher, friends and my family members for their constant encouragement.
Table of Contents Preface Acknowledgement Table of Contents 1. Programming languages. 2. Introduction to java. 3. J2EE 3.1.Servlets
4. 5. 6. 7.
3.1.1. HttpServletRequests 3.1.2. HttpServletResponse 3.1.3. HttpSessions 3.1.4. HttpCookies 3.2.Java Beans 3.3.JSP DBMS 4.1.MySql Ajax Javascript Bibliography
1. Programming languages
A computer programming language is a language used to write compute programs, which involve a computer performing some kind of computation or algorithm and
possibly control external devices such as printers, disk drives, robots, and so on. A programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely. The earliest programming languages predate the invention of the computer, and were used to direct the behavior of machines such as Jacquard looms and player pianos. Thousands of different programming languages have been created, mainly in the computer field, with many more being created every year. Most programming languages describe computation in an imperative style, i.e., as a sequence of commands, although some languages, such as those that support functional programming or logic programming, use alternative forms of description. Computer programming languages are mainly categorized into1. Procedural Programming language. 2. Object Oriented Programming language. Procedural programming can sometimes be used as a synonym for imperative programming (specifying the steps the program must take to reach the desired state), but can also refer (as in this article) to a programming paradigm, derived from structured programming, based upon the concept of the procedure call. Procedures, also known as routines, subroutines, methods, or functions (not to be confused with mathematical functions, but similar to those used in functional programming) simply contain a series of computational steps to be carried out. Any given procedure might be called at any point during a program's execution, including by other procedures or itself.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming
techniques may include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. Many modern programming languages now support OOP, at least as an option. Fundamental features that support the OOP programming style in most objectoriented languages Dynamic dispatch – when a method is invoked on an object, the object itself determines what code gets executed by looking up the method at run time in a table associated with the object. This feature distinguishes an object from an abstract data type (or module), which has a fixed (static) implementation of the operations for all instances. It is a programming methodology that gives modular component development while at the same time being very efficient. Encapsulation (or multi-methods, in which case the state is kept separate) Subtype polymorphism Object inheritance (or delegation) Additional concepts used in object-oriented programming include: Classes of objects Instances of classes Methods which act on the attached objects. Message passing Abstraction
2. Introduction to Java Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and
fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere". Java is currently one of the most popular programming languages in use, particularly for server-client web applications. The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java, GNU Classpath, and Dalvik. There were five primary goals in the creation of the Java language: 1. It should be "simple, object-oriented and familiar". 2. It should be "robust and secure". 3. It should be "architecture-neutral and portable". 4. It should execute with "high performance". 5. It should be "interpreted, threaded, and dynamic". One characteristic of Java is portability, which means that computer programs written in the Java language must run similarly on any supported hardware/operating-system platform. This is achieved by compiling the Java language code to an intermediate representation called Java bytecode, instead of directly to platform-specific machine code. Java bytecode instructions are analogous to machine code, but are intended to be interpreted by a virtual machine (VM) written specifically for the host hardware. End-users commonly use a Java Runtime Environment (JRE) installed on their own machine for standalone Java applications, or in a Web browser for Java applets.
Standardized libraries provide a generic way to access host-specific features such as graphics, threading, and networking. A major benefit of using bytecode is porting. However, the overhead of interpretation means that interpreted programs almost always run more slowly than programs compiled to native executables would. Just-in-Time compilers were introduced from an early stage that compiles bytecodes to machine code during runtime. An edition of the Java platform is the name for a bundle of related programs from Sun that allow for developing and running programs written in the Java programming language. The platform is not specific to any one processor or operating system, but rather an execution engine (called a virtual machine) and a compiler with a set of libraries that are implemented for various hardware and operating systems so that Java programs can run identically on all of them. The Java Platform consists of several programs, each of which provides a distinct portion of its overall capabilities. For example, the Java compiler, which converts Java source code into Java bytecode (an intermediate language for the Java Virtual Machine (JVM)), is provided as part of the Java Development Kit (JDK). The Java Runtime Environment (JRE), complementing the JVM with a just-in-time (JIT) compiler, converts intermediate bytecode into native machine code on the fly. Also supplied are extensive libraries, pre-compiled in which are several other components, some available only in certain editions.
A Java Virtual Machine is a piece of software that is implemented on nonvirtual hardware and on standard operating systems. A JVM provides an environment in which Java bytecode can be executed, enabling such features as automated exception handling, which provides "root-cause" debugging information for every software error (exception), independent of the source code. A JVM is distributed along with a set of standard class libraries that implement the Java application programming interface (API). Appropriate APIs bundled together form the Java Runtime Environment (JRE).The Java Development Kit (JDK) is a Sun Microsystems product aimed at Java
developers. Since the introduction of Java, it has been by far the most widely used Java SDK.
3. J2EE Java Platform, Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming language. The Java platform (Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier Java software, based largely on modular components running on an application server.
Java EE is defined by its specification. As with other Java Community Process specifications, providers must meet certain conformance requirements in order to declare their products as Java EE compliant. Java EE includes several API specifications, such as JDBC, RMI, e-mail, JMS, web services, XML, etc., and defines how to coordinate them. Java EE also features some specifications unique to Java EE for components. These include Enterprise JavaBeans, Connectors, servlets, portlets (following the Java Portlet specification), JavaServer Pages and several web service technologies. This allows developers to create enterprise applications that are portable and scalable, and that integrate with legacy technologies. A Java EE application server can handle transactions, security, scalability, concurrency and management of the components that are deployed to it, in order to enable developers to concentrate more on the business logic of the components rather than on infrastructure and integration tasks.
3.1 Java Servlets A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed via 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. Thus, it can be thought of as a Java Applet that runs on a server instead of a browser.[1] A Servlet is a Java class in Java EE that conforms to the Java Servlet API, a protocol by which a Java class may respond to requests. They are not tied to a specific client-server protocol, but are most often used with the HTTP protocol. Therefore, the word "Servlet" is often used in the meaning of "HTTP Servlet".[2] Thus, a software developer may use a servlet to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML. Servlets are the Java counterpart to non-Java dynamic Web content technologies such as CGI and ASP.NET. Servlets can maintain state in session variables across many server transactions by using HTTP cookies, or URL rewriting. To deploy and run, the Apache Tomcat Server may be used. It is an open source servlet container developed by the Apache Software Foundation (ASF). Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems, and provides a "pure Java" HTTP web server environment for Java code to run. Life cycle of a servlet 1. The container calls the no-arg constructor. 2. The Web container calls the init() method. This method initializes the servlet and must be called before life of a servlet, the init() method is called only once. 3. After initialization, the servlet can service client requests. Each request is serviced in its own separate thread. The Web container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. The developer of the servlet must provide an implementation for these methods. If a request for a method that is not implemented by the servlet
is made, the method of the parent class is called, typically resulting in an error being returned to the requester. 4. Finally, the Web container calls the destroy() method that takes the servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a servlet. The javax.servlet.http package contains a number of interfaces and classes that are commonly used by servlet developers.its functionality makes it easy to build servlets that work with HTTP requests and responses. The following table summarizes the core interfaces that are provided in this packageInterface 1. HttpServletRequ est 2. HttpServletResp onse 3. HttpSession
Description Enables servlets to read data from an Http request. Enables servlets to write data to an Http response. Allows session data to be read and written.
The following table summarizes the core classes that are provided in this package. The most important of these is HttpServlet. Servlet developers typically extend this class in order to process Http Requests. Description
Class 1. Cookie 2. HttpServle t 3. HttpSessio nEvent
Allows state information to be stored on a client machine. Provides methods to handle Httprequests and responses. Encapsulates a session changed event.
3.1.1 HttpServletRequests The HttpServletRequest interface is implemented by the server. It enables a servlet to obtain information about a client request. Extends the ServletRequest interface to provide request information for HTTP servlets. The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
Method Summary java.lang.String - getAuthType() Returns the name of the authentication scheme used to protect the servlet. java.lang.String - getContextPath() Returns the portion of the request URI that indicates the context of the request. Cookie[] getCookies() Returns an array containing all of the Cookie objects the client sent with this request. long getDateHeader(java.lang.String name) Returns the value of the specified request header as a long value that represents a Date object. java.lang.String getHeader(java.lang.String name) Returns the value of the specified request header as a String. java.util.Enumeration getHeaderNames() Returns an enumeration of all the header names this request contains.
java.util.Enumeration getHeaders(java.lang.String name) Returns all the values of the specified request header as an Enumeration of String objects. Int getIntHeader(java.lang.String name) Returns the value of the specified request header as an int. java.lang.String getMethod() Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. java.lang.String getPathInfo() Returns any extra path information associated with the URL the client sent when it made this request. java.lang.String getPathTranslated() Returns any extra path information after the servlet name but before the query string, and translates it to a real path. java.lang.String getQueryString() Returns the query string that is contained in the request URL after the path. java.lang.String getRemoteUser() Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. java.lang.String getRequestedSessionId() Returns the session ID specified by the client. java.lang.String getRequestURI() Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. java.lang.StringBuffer getRequestURL() Reconstructs the URL the client used to make the request.
java.lang.String getServletPath() Returns the part of this request's URL that calls the servlet. HttpSession getSession() Returns the current session associated with this request, or if the request does not have a session, creates one. HttpSession getSession(boolean create) Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session. java.security.Principal getUserPrincipal() Returns a java.security.Principal object containing the name of the current authenticated user. boolean isRequestedSessionIdFromCookie() Checks whether the requested session ID came in as a cookie. boolean isRequestedSessionIdFromUrl() Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL()instead. Boolean isRequestedSessionIdFromURL() Checks whether the requested session ID came in as part of the request URL. boolean isRequestedSessionIdValid() Checks whether the requested session ID is still valid. Boolean isUserInRole java.lang.String role) Returns a boolean indicating whether the authenticated user is included in the specified logical "role".
3.1.2 HttpServletResponse public interface HttpServletResponse
extends ServletResponse Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. For example, it has methods to access HTTP headers and cookies. The servlet container creates an HttpServletResponse object and passes it as an argument to the servlet's service methods (doGet, doPost, etc). The HttpServletResponse interface is implemented by the server. It enables a servlet to formulate an HTTP response to a client. Several constants are defined. These correspond to the different status codes that can be assigned to an HTTP response. For example, SC_OK indicates that the HTTP request succeeded and SC_NOT_FOUND indicates that the requested resource is not available. Field Summary static in SC_ACCEPTED t Status code (202) indicating that a request was accepted for processing, but was not completed. static in SC_BAD_GATEWAY t Status code (502) indicating that the HTTP server received an invalid response from a server it consulted when acting as a proxy or gateway. static in SC_BAD_REQUEST t Status code (400) indicating the request sent by the client was syntactically incorrect. static in SC_CONFLICT t Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource. static in SC_CONTINUE t Status code (100) indicating the client can continue.
static in SC_CREATED t Status code (201) indicating the request succeeded and created a new resource on the server. static in SC_EXPECTATION_FAILED t Status code (417) indicating that the server could not meet the expectation given in the Expect request header. static in SC_FORBIDDEN t Status code (403) indicating the server understood the request but refused to fulfill it. static in SC_FOUND t Status code (302) indicating that the resource reside temporarily under a different URI. static in SC_GATEWAY_TIMEOUT t Status code (504) indicating that the server did not receive a timely response from the upstream server while acting as a gateway or proxy. static in SC_GONE t Status code (410) indicating that the resource is no longer available at the server and no forwarding address is known. static in SC_HTTP_VERSION_NOT_SUPPORTED t Status code (505) indicating that the server does not support or refuses to support the HTTP protocol version that was used in the request message. static in SC_INTERNAL_SERVER_ERROR t Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request. static in SC_LENGTH_REQUIRED t Status code (411) indicating that the request cannot be handled
without a defined Content-Length. static in SC_METHOD_NOT_ALLOWED t Status code (405) indicating that the method specified in the Request-Line is not allowed for the resource identified by the RequestURI. static in SC_MOVED_PERMANENTLY t Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests. static in SC_MOVED_TEMPORARILY t Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource. static in SC_MULTIPLE_CHOICES t Status code (300) indicating that the requested resource corresponds to any one of a set of representations, each with its own specific location. static in SC_NO_CONTENT t Status code (204) indicating that the request succeeded but that there was no new information to return. static in SC_NON_AUTHORITATIVE_INFORMATION t Status code (203) indicating that the meta information presented by the client did not originate from the server. static in SC_NOT_ACCEPTABLE t Status code (406) indicating that the resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.
static in SC_NOT_FOUND t Status code (404) indicating that the requested resource is not available. static in SC_NOT_IMPLEMENTED t Status code (501) indicating the HTTP server does not support the functionality needed to fulfill the request. static in SC_NOT_MODIFIED t Status code (304) indicating that a conditional GET operation found that the resource was available and not modified. static in SC_OK t Status code (200) indicating the request succeeded normally. static in SC_PARTIAL_CONTENT t Status code (206) indicating that the server has fulfilled the partial GET request for the resource. static in SC_PAYMENT_REQUIRED t Status code (402) reserved for future use. static in SC_PRECONDITION_FAILED t Status code (412) indicating that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. static in SC_PROXY_AUTHENTICATION_REQUIRED t Status code (407) indicating that the client MUST first authenticate itself with the proxy. static in SC_REQUEST_ENTITY_TOO_LARGE t Status code (413) indicating that the server is refusing to process the request because the request entity is larger than the server is willing or able to process.
static in SC_REQUEST_TIMEOUT t Status code (408) indicating that the client did not produce a request within the time that the server was prepared to wait. static in SC_REQUEST_URI_TOO_LONG t Status code (414) indicating that the server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. static in SC_REQUESTED_RANGE_NOT_SATISFIABLE t Status code (416) indicating that the server cannot serve the requested byte range. static in SC_RESET_CONTENT t Status code (205) indicating that the agent SHOULD reset the document view which caused the request to be sent. static in SC_SEE_OTHER t Status code (303) indicating that the response to the request can be found under a different URI. static in SC_SERVICE_UNAVAILABLE t Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the request. static in SC_SWITCHING_PROTOCOLS t Status code (101) indicating the server is switching protocols according to Upgrade header. static in SC_TEMPORARY_REDIRECT t Status code (307) indicating that the requested resource resides temporarily under a different URI. static in SC_UNAUTHORIZED t Status code (401) indicating that the request requires HTTP
authentication. static in SC_UNSUPPORTED_MEDIA_TYPE t Status code (415) indicating that the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. static in SC_USE_PROXY t Status code (305) indicating that the requested resource MUST be accessed through the proxy given by the Location field.
Method Summary void addCookie(Cookie cookie) Adds the specified cookie to the response. void addDateHeader(java.lang.String name, long date) Adds a response header with the given name and date-value. void addHeader(java.lang.String name, java.lang.String value) Adds a response header with the given name and value. void addIntHeader(java.lang.String name, int value) Adds a response header with the given name and integer value. boolean containsHeader(java.lang.String name) Returns a boolean indicating whether
the named response header has already been set. java.lang.String encodeRedirectUrl(java.lang.String url) Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead java.lang.String encodeRedirectURL(java.lang.String url) Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. java.lang.String encodeUrl(java.lang.String url) Deprecated. As of version 2.1, use encodeURL(String url) instead java.lang.String encodeURL(java.lang.String url) Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. java.lang.String getHeader(java.lang.String name) Gets the value of the response header with the given name. java.util.Collection Gets the names of the headers of this response. java.util.Collection Gets the values of the response header with the given name. int getStatus() Gets the current status code of this
response. void sendError(int sc) Sends an error response to the client using the specified status code and clears the buffer. void sendError(int sc, java.lang.String msg) Sends an error response to the client using the specified status and clears the buffer. void sendRedirect(java.lang.String location) Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. void setDateHeader(java.lang.String name, long date) Sets a response header with the given name and date-value. void setHeader(java.lang.String name, java.lang.String value) Sets a response header with the given name and value. void setIntHeader(java.lang.String name, int value) Sets a response header with the given name and integer value. void setStatus(int sc) Sets the status code for this response. void setStatus(int sc, java.lang.String sm)
Deprecated. As of version 2.1, due to ambiguous meaning of the message parameter. To set a status code use setStatus(int), to send an error with a description use sendError(int, String). Sets the status code and message for this response.
3.1.3
HTTPSession
javax.servlet.http Interface HttpSession public interface HttpSession Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. The servlet container uses this interface to create a session between an HTTP client and an HTTP server. The session persists for a specified time period, across more than one connection or page request from the user. A session usually corresponds to one user, who may visit a site many times. The server can maintain a session in many ways such as using cookies or rewriting URLs. This interface allows servlets to View and manipulate information about a session, such as the session identifier, creation time, and last accessed time Bind objects to sessions, allowing user information to persist across multiple user connections
When an application stores an object in or removes an object from a session, the session checks whether the object implements HttpSessionBindingListening. If it does, the servlet notifies the object that it has been bound to or unbound from the session. A servlet should be able to handle cases in which the client does not choose to join a session, such as when cookies are intentionally turned off. Until the client joins the session, isNew returns true. If the client chooses not to join the session, getSession will return a different session on each request, and isNew will always return true. Session information is scoped only to the current web application (ServletContext), so information stored in one context will not be directly visible in another. Method Summary java.lang.Object getAttribute(java.lang.String name) Returns the object bound with the specified name in this session, or null if no object is bound under the name. java.util.Enumeratio getAttributeNames() n Returns an Enumeration of String objects containing the names of all the objects bound to this session. long getCreationTime() Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT. java.lang.String getId() Returns a string containing the unique identifier assigned to this session. long getLastAccessedTime() Returns the last time the client sent a request associated with this session, as the number of milliseconds
since midnight January 1, 1970 GMT. int getMaxInactiveInterval() Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. HttpSessionContext getSessionContext() Deprecated. As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API. java.lang.Object getValue(java.lang.String name) Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String). java.lang.String[] getValueNames() Deprecated. As of Version 2.2, this method is replaced by getAttributeNames(). void invalidate() Invalidates this session and unbinds any objects bound to it. boolean isNew() Returns true if the client does not yet know about the session or if the client chooses not to join the session. void putValue(java.lang.String name, java.lang.Object value) Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.object) void removeAttribute(java.lang.String name) Removes the object bound with the specified name from this session.
void removeValue(java.lang.String name) Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String,java.lang.object) void setAttribute(java.lang.String name, java.lang.Object value) Binds an object to this session, using the name specified. void setMaxInactiveInterval(int interval) Specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
Method Summary. getCreationTime public long getCreationTime() Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT. Returns: a long specifying when this session was created, expressed in milliseconds since 1/1/1970 GMT Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
getId public java.lang.String getId()
Returns a string containing the unique identifier assigned to this session. The identifier is assigned by the servlet container and is implementation dependent. Returns: a string specifying the identifier assigned to this session
getLastAccessedTime public long getLastAccessedTime() Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT. Actions that your application takes, such as getting or setting a value associated with the session, do not affect the access time. Returns: a long representing the last time the client sent a request associated with this session, expressed in milliseconds since 1/1/1970 GMT
setMaxInactiveInterval public void setMaxInactiveInterval(int interval) Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout. Parameters: interval - An integer specifying the number of seconds
getMaxInactiveInterval public int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. After this interval, the servlet container will invalidate the session. The maximum time interval can be set with the setMaxInactiveInterval method. A negative time indicates the session should never timeout. Returns: an integer specifying the number of seconds this session remains open between client requests See Also: setmaxInactiveInterval(int)
getSessionContext public HttpSessionContext getSessionContext() Deprecated. As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API.
getAttribute public java.lang.Object getAttribute(java.lang.String name) Returns the object bound with the specified name in this session, or null if no object is bound under the name. Parameters: name - a string specifying the name of the object Returns: the object with the specified name Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
getValue public java.lang.Object getValue(java.lang.String name) Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String). Parameters: name - a string specifying the name of the object Returns: the object with the specified name Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
getAttributeNames public java.util.Enumeration getAttributeNames() Returns an Enumeration of String objects containing the names of all the objects bound to this session. Returns: an Enumeration of String objects specifying the names of all the objects bound to this session Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
getValueNames public java.lang.String[] getValueNames()
Deprecated. As of Version 2.2, this method is replaced by getAttributeNames() Returns: an array of String objects specifying the names of all the objects bound to this session Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
setAttribute public void setAttribute(java.lang.String name, java.lang.Object value) Binds an object to this session, using the name specified. If an object of the same name is already bound to the session, the object is replaced. After this method executes, and if the object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueBound. Parameters: name - the name to which the object is bound; cannot be null value - the object to be bound; cannot be null Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
putValue public void putValue(java.lang.String name, java.lang.Object value)
Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String) Parameters: name - the name to which the object is bound; cannot be null value - the object to be bound; cannot be null Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
removeAttribute public void removeAttribute(java.lang.String name) Removes the object bound with the specified name from this session. If the session does not have an object bound with the specified name, this method does nothing. After this method executes, and if the object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueUnbound. Parameters: name - the name of the object to remove from this session Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
removeValue public void removeValue(java.lang.String name)
Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String,java.lang.object) Parameters: name - the name of the object to remove from this session Throws: java.lang.IllegalStateException - if this method is called on an invalidated session
invalidate public void invalidate() Invalidates this session and unbinds any objects bound to it. Throws: java.lang.IllegalStateException - if this method is called on an already invalidated session
isNew public boolean isNew() Returns true if the client does not yet know about the session or if the client chooses not to join the session. For example, if the server used only cookiebased sessions, and the client had disabled the use of cookies, then a session would be new on each request. Returns: true if the server has created a session, but the client has not yet joined Throws: java.lang.IllegalStateException - if this method is called on an already invalidated session.
3.1.4 Cookies A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is used for an origin website to send state information to a user's browser and for the browser to return the state information to the origin site. The state information can be used for authentication, identification of a user session, user's preferences, shopping cart contents, or anything else that can be accomplished through storing text data. Cookies are not software. They cannot be programmed, cannot carry viruses, and cannot install malware on the host computer . However, they can be used by spyware to track user's browsing activities – a major privacy concern that prompted European and US law makers to take actions. Cookies could also be stolen by hackers to gain access to a victim's web account.
java.net Class HttpCookie java.lang.Object java.net.HttpCookie All Implemented Interfaces: Cloneable An HttpCookie object represents an http cookie, which carries state information between server and user agent. Cookie is widely adopted to create stateful sessions.
Method Summary Object clone() Create and return a copy of this object. static boolean domainMatches(String domain, String host) The utility method to check whether a host name is
in a domain or not. boolean equals(Object obj) Test the equality of two http cookies. String getComment() Returns the comment describing the purpose of this cookie, or null if the cookie has no comment. String getCommentURL() Returns the comment url describing the purpose of this cookie, or null if the cookie has no comment url. boolean getDiscard() Return the discard attribute of the cookie String getDomain() Returns the domain name set for this cookie. long getMaxAge() Returns the maximum age of the cookie, specified in seconds. String getName() Returns the name of the cookie. String getPath() Returns the path on the server to which the browser returns this cookie. String getPortlist() Return the port list attribute of the cookie boolean getSecure() Returns true if sending this cookie should be restricted to a secure protocol, or false if the it can be
sent using any protocol. String getValue() Returns the value of the cookie. int getVersion() Returns the version of the protocol this cookie complies with. boolean hasExpired() Reports whether this http cookie has expired or not. int hashCode() Return hash code of this http cookie. static List Constructs cookies from set-cookie or set-cookie2 header string. void setComment(String purpose) Specifies a comment that describes a cookie's purpose. void setCommentURL(String purpose) Specifies a comment url that describes a cookie's purpose. void setDiscard(boolean discard) Specify whether user agent should discard the cookie unconditionally. void setDomain(String pattern) Specifies the domain within which this cookie should be presented.
void setMaxAge(long expiry) Sets the maximum age of the cookie in seconds. void setPath(String uri) Specifies a path for the cookie to which the client should return the cookie. void setPortlist(String ports) Specify the portlist of the cookie, which restricts the port(s) to which a cookie may be sent back in a Cookie header. void setSecure(boolean flag) Indicates whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL. void setValue(String newValue) Assigns a new value to a cookie after the cookie is created. void setVersion(int v) Sets the version of the cookie protocol this cookie complies with. String toString() Constructs a cookie header string representation of this cookie, which is in the format defined by corresponding cookie specification, but without the leading "Cookie:" token.
3.2 Java Beans JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods. In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behaviour. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans. The required conventions are as follows: The class must have a public default constructor (no-argument). This allows easy instantiation within editing and activation frameworks. The class properties must be accessible using get, set, is (used for boolean properties instead of get) and other methods (so-called accessor methods and mutator methods), following a standard naming-convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties. The class should be serializable. It allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion independent of the VM and of the platform.
JavaBeans™ is a portable, platform-independent component model written in the Java programming language. The JavaBeans architecture was built through a collaborative industry effort and enables developers to write reusable components in the Java programming language. With the JavaBeans API you can create reuseable, platform-independent components. Using JavaBeanscompliant application builder tools, you can combine these components into applets, applications, or composite components. JavaBean components are known as beans. Beans are dynamic in that they can be changed or customized. A bean information class implements the BeanInfo interface. A BeanInfo class explicitly lists those bean features that are to be exposed to application builder tools. Properties are the appearance and behavior characteristics of a bean that can be changed at design time. Builder tools introspect on a bean to discover its properties and expose those properties for manipulation. Beans expose properties so they can be customized at design time. Customization is supported in two ways: by using property editors, or by using more sophisticated bean customizers. Beans use events to communicate with other beans. A bean that is to receive events (a listener bean) registers with the bean that fires the event (a source bean). Builder tools can examine a bean and determine which events that bean can fire (send) and which it can handle (receive). Persistence enables beans to save and restore their state. After changing a bean's properties, you can save the state of the bean and restore that bean at a later time with the property changes intact. The JavaBeans architecture uses Java Object Serialization to support persistence. A bean's methods are no different from Java methods, and can be called from other beans or a scripting environment. By default all public methods are exported.
3.3 JSP(Java Server Page)
JavaServer Pages (JSP) is a Java technology that helps software developers serve dynamically generated web pages based on HTML, XML, or other document types. Released in 1999 as Sun's answer to ASP and PHP, JSP was designed to address the perception that the Java programming environment didn't provide developers with enough support for the Web. To deploy and run, a compatible web server with servlet container is required. The Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems and the JCP must both be met by the container. Architecturally, JSP may be viewed as a high-level abstraction of Java servlets. JSP pages are loaded in the server and are operated from a structured special installed Java server packet called a Java EE Web Application, often packaged as a .war or .ear file archive. JSP allows Java code and certain pre-defined actions to be interleaved with static web markup content, with the resulting page being compiled and executed on the server to deliver an HTML or XML document. The compiled pages and any dependent Java libraries use Java bytecode rather than a native software format, and must therefore be executed within a Java virtual machine (JVM) that integrates with the host operating system to provide an abstract platform-neutral environment. JSP syntax is a fluid mix of two basic content forms: scriptlet elements and markup. Markup is typically standard HTML or XML, while scriptlet elements are delimited blocks of Java code which may be intermixed with the markup. When the page is requested the Java code is executed and its output is added, in situ, with the surrounding markup to create the final page. JSP pages must be compiled to Java bytecode classes before they can be executed, but such compilation is needed only when a change to the source JSP file has occurred. Java code is not required to be complete (self contained) within its scriptlet element block, but can straddle markup content providing the page as a whole is syntactically correct (for example, any Java if/for/while blocks opened in one scriptlet element must be correctly closed in a later element for the page to successfully compile). This system of split inline coding sections is called step
over scripting because it can wrap around the static markup by stepping over it. Markup which falls inside a split block of code is subject to that code, so markup inside an if block will only appear in the output when the if condition evaluates to true; likewise markup inside a loop construct may appear multiple times in the output depending upon how many times the loop body runs. The JSP syntax adds additional XML-like tags, called JSP actions, to invoke builtin functionality. Additionally, the technology allows for the creation of JSP tag libraries that act as extensions to the standard HTML or XML tags. JVM operated tag libraries provide a platform independent way of extending the capabilities of a web server. Note that not all commercial Java servers are Java EE specification compliant.
JavaServer Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side development. JSP files are HTML files with special Tags containing Java source code that provide the dynamic content.The following shows the Typical Web server,different clients connecting via the Internet to a Web server. In this example,the Web server is running on Unix and is the very popular Apache Web server.
First static web pages were displayed. Typically these were people?s first experience with making web pages so consisted of My Home Page sites and company marketing information. Afterwards Perl and C were languages used on the web server to provide dynamic content. Soon most languages including Visualbasic,Delphi,C and Java could be used to write applications that provided dynamic content using data from text files or database requests. These were known
as CGI server side applications. ASP was developed by Microsoft to allow HTML developers to easily provide dynamic content supported as standard by Microsoft?s free Web Server,Internet Information Server (IIS). JSP is the equivalent from Sun Microsystems,a comparison of ASP and JSP will be presented in the following section. The following diagram shows a web server that supports JSP files. Notice that the web server also is connected to a database.
JSP is easy to learn and allows developers to quickly produce web sites and applications in an open and standard way. JSP is based on Java,an object-oriented language. JSP offers a robust platform for web development.
Main reasons to use JSP: Multi platform. Component reuse by using Javabeans and EJB. Advantages of Java. You can take one JSP file and move it to another platform,web server or JSP Servlet engine.
This means you are never locked into one vendor or platform. HTML and graphics displayed on the web browser are classed as the presentation layer. The Java code (JSP) on the server is classed as the implementation. By having a separation of presentation and implementation,web designers work only on the presentation and Java developers concentrate on implementing the application. JSP architecture
JSPs are built on top of SUN Microsystems' servlet technology. JSPs are essential an HTML page with special JSP tags embedded. These JSP tags can contain Java code. The JSP file extension is .jsp rather than .htm or .html. The JSP engine parses the .jsp and creates a Java servlet source file. It then compiles the source file into a class file,this is done the first time and this why the JSP is probably slower the first
time it is accessed. Any time after this the special compiled servlet is executed and is therefore returns faster.
Steps required for a JSP request: 1. The user goes to a web site made using JSP. The user goes to a JSP page (ending with .jsp). The web browser makes the request via the Internet. 2. The JSP request gets sent to the Web server. 3. The Web server recognises that the file required is special (.jsp),therefore passes the JSP file to the JSP Servlet Engine. 4. If the JSP file has been called the first time,the JSP file is parsed,otherwise go to step 7. 5. The next step is to generate a special Servlet from the JSP file. All the HTML required is converted to println statements.
6. The Servlet source code is compiled into a class. 7. The Servlet is instantiated,calling the init and service methods.
4. DBMS A Database Management System (DBMS) is a software package with computer programs that control the creation, maintenance, and the use of a database. It allows organizations to conveniently develop databases for various applications by database administrators (DBAs) and other specialists. A database is an integrated collection of data records, files, and other database objects. A DBMS allows different user application programs to concurrently access the same database.
DBMSs may use a variety of database models, such as the relational model or object model, to conveniently describe and support applications. It typically supports query languages, which are in fact high-level programming languages, dedicated database languages that considerably simplify writing database application programs. Database languages also simplify the database organization as well as retrieving and presenting information from it. A DBMS provides facilities for controlling data access, enforcing data integrity, managing concurrency control, recovering the database after failures and restoring it from backup files, as well as maintaining database security. A DBMS is a set of software programs that controls the system organization, storage, management, and retrieval of data in a database. DBMSs are categorized according to their data structures or types. The DBMS accepts requests for data from an application program and instructs the operating system to transfer the appropriate data. The queries and responses must be submitted and received according to a format that conforms to one or more applicable protocols. When a DBMS is used, information systems can be changed more easily as the
organization's information requirements change. New categories of data can be added to the database without disruption to the existing system. Database servers are dedicated computers that hold the actual databases and run only the DBMS and related software. Database servers are usually multiprocessor computers, with generous memory and RAID disk arrays used for stable storage. Hardware database accelerators, connected to one or more servers via a high-speed channel, are also used in large volume transaction processing environments. DBMSs are found at the heart of most database applications. DBMSs may be built around a custom multitasking kernel with built-in networking support, but modern DBMSs typically rely on a standard operating system to provide these functions. IBM started working on a prototype system loosely based on Codd's concepts as System R in the early 1970s. The first version was ready in 1974/5, and work then started on multi-table systems in which the data could be split so that all of the data for a record (some of which is optional) did not have to be stored in a single large "chunk". Subsequent multi-user versions were tested by customers in 1978 and 1979, by which time a standardized query language - SQL - had been added. Codd's ideas were establishing themselves as both workable and superior to Codasyl, pushing IBM to develop a true production version of System R, known as SQL/DS, and, later, Database 2 (DB2). Many of the people involved with INGRES became convinced of the future commercial success of such systems, and formed their own companies to commercialize the work but with an SQL interface. Sybase, Informix, NonStop SQL and eventually Ingres itself were all being sold as offshoots to the original INGRES product in the 1980s. Even Microsoft SQL Server is actually a re-built version of Sybase, and thus, INGRES. Only Larry Ellison's Oracle started from a different chain, based on IBM's papers on System R, and beat IBM to market when the first version was released in 1978. Stonebraker went on to apply the lessons from INGRES to develop a new database, Postgres, which is now known as PostgreSQL. PostgreSQL is often used for global mission critical applications (the .org and .info domain name registries use it as their primary data store, as do many large companies and financial institutions).
In Sweden, Codd's paper was also read and Mimer SQL was developed from the mid-70s at Uppsala University. In 1984, this project was consolidated into an independent enterprise. In the early 1980s, Mimer in c introduced transaction handling for high robustness in applications, an idea that was subsequently implemented on most other DBMS.
Components DBMS Engine accepts logical requests from various other DBMS subsystems, converts them into physical equivalents, and actually accesses the database and data dictionary as they exist on a storage device. Data Definition Subsystem helps the user create and maintain the data dictionary and define the structure of the files in a database. Data Manipulation Subsystem helps the user to add, change, and delete information in a database and query it for valuable information. Software tools within the data manipulation subsystem are most often the primary interface between user and the information contained in a database. It allows the user to specify its logical information requirements. Application Generation Subsystem contains facilities to help users develop transaction-intensive applications. It usually requires that the user perform a detailed series of tasks to process a transaction. It facilitates easyto-use data entry screens, programming languages, and interfaces.
Data Administration Subsystem helps users manage the overall database environment by providing facilities for backup and recovery, security management, query optimization, concurrency control, and change management.
Modeling language A modeling language is a data modeling language to define the schema of each database hosted in the DBMS, according to the DBMS database model. Database management systems (DBMS) are designed to use one of five database structures
to provide simplistic access to information stored in databases. The five database structures are: the hierarchical model, the network model, the relational model, the multidimensional model, and the object model. Inverted lists and other methods are also used. A given database management system may provide one or more of the five models. The optimal structure depends on the natural organization of the application's data, and on the application's requirements, which include transaction rate (speed), reliability, maintainability, scalability, and cost. The hierarchical structure was used in early mainframe DBMS. Records’ relationships form a treelike model. This structure is simple but nonflexible because the relationship is confined to a one-to-many relationship. IBM’s IMS system and the RDM Mobile are examples of a hierarchical database system with multiple hierarchies over the same data. RDM Mobile is a newly designed embedded database for a mobile computer system. The hierarchical structure is used primarily today for storing geographic information and file systems. The network structure consists of more complex relationships. Unlike the hierarchical structure, it can relate to many records and accesses them by following one of several paths. In other words, this structure allows for many-to-many relationships. The relational structure is the most commonly used today. It is used by mainframe, midrange and microcomputer systems. It uses two-dimensional rows and columns to store data. The tables of records can be connected by common key values. While working for IBM, E.F. Codd designed this structure in 1970. The
model is not easy for the end user to run queries with because it may require a complex combination of many tables. The multidimensional structure is similar to the relational model. The dimensions of the cube-like model have data relating to elements in each cell. This structure gives a spreadsheet-like view of data. This structure is easy to maintain because records are stored as fundamental attributes - in the same way they are viewed - and the structure is easy to understand. Its high performance has made it the most popular database structure when it comes to enabling online analytical processing (OLAP). The object oriented structure has the ability to handle graphics, pictures, voice and text, types of data, without difficultly unlike the other database structures. This structure is popular for multimedia Web-based applications. It was designed to work with object-oriented programming languages such as Java. The dominant model in use today is the ad hoc one embedded in SQL,despite the objections of purists who believe this model is a corruption of the relational model since it violates several fundamental principles for the sake of practicality and performance. Many DBMSs also support the Open Database Connectivity API that supports a standard way for programmers to access the DBMS. Before the database management approach, organizations relied on file processing systems to organize, store, and process data files. End users criticized file processing because the data is stored in many different files and each organized in a different way. Each file was specialized to be used with a specific application. File processing was bulky, costly and nonflexible when it came to supplying needed data accurately and promptly. Data redundancy is an issue with the file processing system because the independent data files produce duplicate data so when updates were needed each separate file would need to be updated. Another issue is the lack of data integration. The data is dependent on other data to organize and store it. Lastly, there was not any consistency or standardization of the data in a file processing system which makes maintenance difficult. For these reasons, the database management approach was produced. Data structure
Data structures (fields, records, files and objects) optimized to deal with very large amounts of data stored on a permanent data storage device (which implies relatively slow access compared to volatile main memory).
4.1 SQL SQL , often referred to as Structured Query Language, is a database computer declarative language designed for managing data in relational database management systems (RDBMS), and originally based upon relational algebra and tuple relational calculus. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control. SQL was one of the first commercial languages for Edgar F. Codd's relational model, as described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data Banks".Despite not adhering to the relational model as described by Codd, it became the most widely used database language. The SQL language is sub-divided into several language elements, including: Clauses, which are constituent components of statements and queries. (In some cases, these are optional.) Expressions, which can produce either scalar values or tables consisting of columns and rows of data. Predicates, which specify conditions that can be evaluated to SQL three-valued logic (3VL) or Boolean (true/false/unknown) truth values and which are used to limit the effects of statements and queries, or to change program flow. Queries, which retrieve the data based on specific criteria. This is the most important element of SQL. Statements, which may have a persistent effect on schemata and data, or which may control transactions, program flow, connections, sessions, or diagnostics.
o SQL statements also include the semicolon (";") statement terminator. Though not required on every platform, it is defined as a standard part of the SQL grammar. Insignificant whitespace is generally ignored in SQL statements and queries, making it easier to format SQL code for readability. The most common operation in SQL is the query, which is performed with the declarative SELECT statement. SELECT retrieves data from one or more tables, or expressions. Standard SELECT statements have no persistent effects on the database. Some non-standard implementations of SELECT can have persistent effects, such as the SELECT INTO syntax that exists in some databases. Queries allow the user to describe desired data, leaving the database management system (DBMS) responsible for planning, optimizing, and performing the physical operations necessary to produce that result as it chooses. A query includes a list of columns to be included in the final result immediately following the SELECT keyword. An asterisk ("*") can also be used to specify that the query should return all columns of the queried tables. SELECT is the most complex statement in SQL, with optional keywords and clauses that include: The FROM clause which indicates the table(s) from which data is to be retrieved. The FROM clause can include optional JOIN subclauses to specify the rules for joining tables. The WHERE clause includes a comparison predicate, which restricts the rows returned by the query. The WHERE clause eliminates all rows from the result set for which the comparison predicate does not evaluate to True. The GROUP BY clause is used to project rows having common values into a smaller set of rows. GROUP BY is often used in conjunction with SQL aggregation functions or to eliminate
duplicate rows from a result set. The WHERE clause is applied before the GROUP BY clause. The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause. Because it acts on the results of the GROUP BY clause, aggregation functions can be used in the HAVING clause predicate. The ORDER BY clause identifies which columns are used to sort the resulting data, and in which direction they should be sorted (options are ascending or descending). Without an ORDER BY clause, the order of rows returned by an SQL query is undefined. What Can SQL do?
SQL can execute queries against a database SQL can retrieve data from a database SQL can insert records in a database SQL can update records in a database SQL can delete records from a database SQL can create new databases SQL can create new tables in a database SQL can create stored procedures in a database SQL can create views in a database SQL can set permissions on tables, procedures, and views
5. Ajax
Ajax an acronym for asynchronous JavaScript and XML is a group of interrelated web development methods used on the client-side to create interactive web applications. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data are usually retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not needed (JSON is often used instead), and the requests need not be asynchronous. Like DHTML and LAMP, Ajax is not one technology, but a group of technologies. Ajax uses a combination of HTML and CSS to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and to allow the user to interact with the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads. The term Ajax has come to represent a broad group of web technologies that can be used to implement a web application that communicates with a server in the background, without interfering with the current state of the page. In the article that coined the term Ajax, Jesse James Garrett explained that the following technologies are incorporated: HTML or XHTML and CSS for presentation the Document Object Model (DOM) for dynamic display of and interaction with data XML for the interchange of data, and XSLT for its manipulation the XMLHttpRequest object for asynchronous communication JavaScript to bring these technologies together
Since then, however, there have been a number of developments in the technologies used in an Ajax application, and the definition of the term Ajax. In particular, it has been noted that JavaScript is not the only client-side scripting language that can be used for implementing an Ajax application; other languages such as VBScript are also capable of the required functionality. (However, JavaScript is the most popular language for Ajax programming due to its inclusion in and compatibility with the majority of modern web browsers.) Also, XML is not required for data interchange and therefore XSLT is not required for the manipulation of data. JavaScript Object Notation (JSON) is often used as an alternative format for data interchange, although other formats such as preformatted HTML or plain text can also be used.
How AJAX Works
AJAX is Based on Internet Standards AJAX is based on internet standards, and uses a combination of:
XMLHttpRequest object (to exchange data asynchronously with a server)
JavaScript/DOM (to display/interact with the information)
CSS (to style the data)
XML (often used as the format for transferring data)
AJAX applications are browser- and platform-independent!
Some uses for Ajax interactions are the following: Real-time form data validation: Form data such as user IDs, serial numbers, postal codes, or even special coupon codes that require server-side validation can be validated in a form before the user submits a form. See Realtime Form Validation for details. Autocompletion: A specific portion of form data such as an email address, name, or city name may be autocompleted as the user types. Load on demand: Based on a client event, an HTML page can fetch more data in the background, allowing the browser to load pages more quickly. Sophisticated user interface controls and effects: Controls such as trees, menus, data tables, rich text editors, calendars, and progress bars allow for better user interaction and interaction with HTML pages, generally without requiring the user to reload the page. Refreshing data and server push: HTML pages may poll data from a server for up-to-date data such as scores, stock quotes, weather, or application-specific data. A client may use Ajax techniques to get a set of current data without reloading a full page. Polling is not the most effecient means of ensuring that data on a page is the most current. Emerging techniques such as Comet are being developed to provide true server-side push over HTTP by keeping a persistent connection between the client and server. See this blog entry on Comet using Grizzly for more on the development of server push with Java technology.
Partial submit: An HTML page can submit form data as needed without requiring a full page refresh. Mashups: An HTML page can obtain data using a server-side proxy or by including an external script to mix external data with your application's or your service's data. For example, you can mix content or data from a thirdparty application such as Google Maps with your own application. Page as an application: Ajax techniques can be made to create single-page applications that look and feel much like a desktop application. See the article on the use of Ajax and portlets for more on how you can use portlet applications today. Though not all-inclusive, this list shows that Ajax interactions allow web applications to do much more than they have done in the past. How Ajax is Different An Ajax application eliminates the start-stop-start-stop nature of interaction on the Web by introducing an intermediary—an Ajax engine—between the user and the server. It seems like adding a layer to the application would make it less responsive, but the opposite is true. Instead of loading a webpage, at the start of the session, the browser loads an Ajax engine—written in JavaScript and usually tucked away in a hidden frame. This engine is responsible for both rendering the interface the user sees and communicating with the server on the user’s behalf. The Ajax engine allows the user’s interaction with the application to happen asynchronously—independent of communication with the server. So the user is never staring at a blank browser
window and an hourglass icon, waiting around for the server to do something.
Figure 2: The synchronous interaction pattern of a traditional web application (top) compared with the asynchronous pattern of an Ajax application (bottom). Every user action that normally would generate an HTTP request takes the form of a JavaScript call to the Ajax engine instead. Any response to a user action that
doesn’t require a trip back to the server—such as simple data validation, editing data in memory, and even some navigation—the engine handles on its own. If the engine needs something from the server in order to respond—if it’s submitting data for processing, loading additional interface code, or retrieving new data—the engine makes those requests asynchronously, usually using XML, without stalling a user’s interaction with the application.
6. Javascript JavaScript, also known as ECMAScript, is a prototype-based, object-oriented scripting language that is dynamic, weakly typed and has first-class functions. It is also considered a functional programming. JavaScript is an implementation of the ECMAScript language standard and is primarily used in the form of client-side JavaScript, implemented as part of a web browser in order to provide enhanced user interfaces and dynamic websites. This enables programmatic access to computational objects within a host environment.JavaScript's use in applications outside web pages—for example in PDF documents, site-specific browsers and desktop widgets—is also significant. Newer and faster JavaScript VMs and frameworks built upon them (notably Node.js) have also increased the popularity of JavaScript for server-side web apps.JavaScript uses syntax influenced by that of C. JavaScript copies many names and naming conventions from Java, but the two languages are otherwise unrelated and have very different semantics. FeaturesThe following features are common to all conforming ECMAScript implementations, unless explicitly specified otherwise. Imperative and structured JavaScript supports structured programming syntax in C (e.g., if statements, while loops, switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not supported (instead, JavaScript has function-level
scoping). JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C, JavaScript makes a distinction between expressions and statements. One syntactic difference from C is automatic semicolon insertion, in which the semicolons that terminate statements can be omitted. Dynamic Dynamic typing As in most scripting languages, types are associated with values, not with variables. For example, a variable x could be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type of an object, including duck typing. Object based JavaScript is almost entirely object-based. JavaScript objects are associative arrays, augmented with prototypes (see below). Object property names are string keys: obj.x = 10 and obj['x'] = 10 are equivalent, the dot notation being syntactic sugar. Properties and their values can be added, changed, or deleted at run-time. Most properties of an object (and those on its prototype inheritance chain) can be enumerated using a for...in loop. JavaScript has a small number of built-in objects such as Function and Date. Run-time evaluation JavaScript includes an eval function that can execute statements provided as strings at run-time. Functional First-class functions Functions are first-class; they are objects themselves. As such, they have properties and methods, such as length and
call(); and they can be assigned to variables, passed as arguments, returned by other functions, and manipulated like any other object. Any reference to a function allows it to be invoked using the () operator. Nested functions 'Inner' or 'nested' functions are functions defined within another function. They are created each time the outer function is invoked. In addition to that, the scope of the outer function, including any constants, local variables and argument values, become part of the internal state of each inner function object, even after execution of the outer function concludes. Closures JavaScript allows nested functions to be created, with the lexical scope in force at their definition, and has a () operator to invoke them now or later. This combination of code that can be executed outside the scope in which it is defined, with its own scope to use during that execution, is called a closure in computer science. Prototype-based Prototypes JavaScript uses prototypes instead of classes for inheritance. It is possible to simulate many class-based features with prototypes in JavaScript. functions as object constructors Functions double as object constructors along with their typical role. Prefixing a function call with new creates a new object and calls that function with its local this keyword bound to that object for that invocation. The constructor's
prototype property determines the object used for the new object's internal prototype. JavaScript's built-in constructors, such as Array, also have prototypes that can be modified. Functions as methods Unlike many object-oriented languages, there is no distinction between a function definition and a method definition. Rather, the distinction occurs during function calling; a function can be called as a method. When a function is called as a method of an object, the function's local this keyword is bound to that object for that invocation. Miscellaneous Run-time environment JavaScript typically relies on a run-time environment (e.g. in a web browser) to provide objects and methods by which scripts can interact with "the outside world". In fact, it relies on the environment to provide the ability to include/import scripts (e.g. HTML elements). (This is not a language feature per se, but it is common in most JavaScript implementations.) Array and object literals Like many scripting languages, arrays and objects (associative arrays in other languages) can each be created with a succinct shortcut syntax. In fact, these literals form the basis of the JSON data format. Regular expressions JavaScript also supports regular expressions in a manner similar to Perl, which provide a concise and powerful syntax
for text manipulation that is more sophisticated than the built-in string functions. Vendor-specific extensions JavaScript is officially managed by Mozilla Foundation, and new language features are added periodically. However, only some non-Mozilla JavaScript engines support these new features: property getter and setter functions (also supported by WebKit, Opera, ActionScript, and Rhino) conditional catch clauses iterator protocol adopted from Python shallow generators/coroutines also adopted from Python array comprehensions and generator expressions also adopted from Python proper block scope via the new let keyword array and object destructuring (limited form of pattern matching) concise function expressions (function(args) expr) ECMAScript for XML (E4X), an extension that adds native XML support to ECMAScript.
View more...
Comments