An Introduction To Java Enterprise Edition - انجمن جاواکاپ

1y ago
32 Views
2 Downloads
1.63 MB
116 Pages
Last View : 12d ago
Last Download : 3m ago
Upload by : Isobel Thacker
Transcription

Enterprise ApplicationDevelopmentAn Introduction toJava Enterprise EditionShahid Beheshti UniversitySadegh Aliakbary

OutlineEnterprise Application DevelopmentWeb ProgrammingJava Enterprise Edition 2ArchitecturesPatternsStandardsTechnologiesSadegh AliakbaryJavaEE

Static Web PagesHTML FilesWeb gh AliakbaryJavaEE

Dynamic Web PagesWeb ServerBrowserFormSubmit Form4Sadegh AliakbaryJavaEE

Web ApplicationDefinition: A web application is an applicationdelivered to users from a web server over a networksuch as the InternetOnly needs a web browser to use the application(Thin Client) Software application that is coded in a browser-supportedlanguageCommon web applications, e.g., webmail, GoogleDocs, Portals, 5Sadegh AliakbaryJavaEE

Web Applications Layers Logical Partitioning LayeringCommon layering in web applications Presentation LayerBusiness logic LayerData (management/source) LayerThese layers are purely abstractionsThese layers may not correspond to physical distribution(tiers)6Sadegh AliakbaryJavaEE

Presentation Layer Handling the interactions between the user and thesoftware GUIHTML based browserThe user interface of the application Can be made up client side & server side codes It communicates with other layers by outputtingresults to the browser/client software and all otherlayers What is this layer in Facebook?7Sadegh AliakbaryJavaEE

Business Logic LayerThe work that the application needs to do for thedomainIt controls an application’s functionality by performingdetailed processing Validation of the data from the tching data source logic What does this layer do in Facebook? 8Sadegh AliakbaryJavaEE

Data Layer Communicating with other systems that carry outtasks (typically data retrieval) on behalf of theapplicationDatabase serverFilesTransaction monitor What is this layer in Facebook? 9Sadegh AliakbaryJavaEE

Multilayer ArchitecturePresentation LayerBusiness logic LayerData Layer10Sadegh AliakbaryJavaEE

Data Layer Trends New Patterns and technologies in data layer: Object DatabasesORMNoSQLCQRS Command Query Responsibility SegregationData-warehousing11Sadegh AliakbaryJavaEE

Client-Server Architecture Client-Server: The traditional architecture for distributedcomputing (including web)Client: Active (master), Sends requests, Awaits responseServer: passive (slave), waits for requests, serves requests andsends a response Thin client (Pros and Cons?) function is mainly presentational e.g. standard browser functionalityAll significant processing done by serverFat client (Pros and Cons?) 12Significant processing on client e.g. Java applet, Flashless server loadSadegh AliakbaryJavaEE

Multitier Architecture Physical separation of these layers is another story Tiers: the physical separation of layersThree-tier Architecture:N-tire Architecture:13Sadegh AliakbaryJavaEE

Three-Tier (Web Server) Browser handles presentation logicBrowser talks to Web server via HTTP protocolBusiness logic and data model are handled by“dynamic contents generation” technologies (CGI,Servlet/JSP, ASP)14Sadegh AliakbaryJavaEE

N-Tier Architecture In N-tier deployments, presentation layer,business logic layer, and data layer areseparated into respective physical tiers Presentation layer is implemented by parts inboth client & server sides 3 tier: client server data baseE.g., dynamic web page using AJAX PHP4 tier: Browser Web server Application Server Database serverComplicated Bussing logic layer itself can bedistributed multitier application N-tier15Sadegh AliakbaryJavaEE

Typical Web ApplicationN-tier ArchitectureHTMLClient(browser)Web ServerApplicationServer16Sadegh AliakbaryDatabaseServerJavaEE

N-Tier Architecture Characteristics Migration costs are low Business logic application migrationDatabase switchingWeb server switchOS upgradeEach tier can be upgraded independently Communication performance suffers Maintenance costs are high17Sadegh AliakbaryJavaEE

Application servers Many common requirements in applications These are not implemented by neither OS norApplication developer Transaction, Logging and audit, Security, and much moreThey are called middlewareApplication servers provide middleware services 18Application components live inside application serversSadegh AliakbaryJavaEE

Application Servers Existing technologies can be classified into three broadcategoriesJava based platform (Java Enterprise Edition).NET FrameworkOther web application development frameworks 19PHP frameworks: Zend, Ruby on Rail Sadegh AliakbaryJavaEE

Java Enterprise Edition20Sadegh AliakbaryJavaEE

The Enterprise Today Availability7 24 Performance Extensibility Security Scalability IntegrationEenterprise- a project, typically one that is difficult or requires effort.- a business or company.21Sadegh AliakbaryJavaEE

The Java Platform22Sadegh AliakbaryJavaEE

The Java Platform23Sadegh AliakbaryJavaEE

Java EE Java Platforms Java Card: Smart card versionJava ME (Micro Edition): Embedded systems, e.g. MobilehandheldJava SE (Standard Edition): Desktop applicationdevelopmentJava EE (Enterprise Edition): Enterprise distributedapplication softwareJava EE add standards and libraries to SE for faulttolerant, distributed, multi-tier based components 24Until java 5, it has been called J2EESadegh AliakbaryJavaEE

JavaEE JavaEE platform is a simple, unified standard fordistributed applications through a componentbased application modelProvides a component-based approach to thedesign, development, assembly, and deployment ofenterprise applicationsIt’s based on 3 -tier Application Architecture25Sadegh AliakbaryJavaEE

JavaEE Application ArchitectureUser InterfaceApplication Logic26Sadegh AliakbaryJavaEE

J2EE Components J2EE Client Web Client(DHTML,HTML,XML,.)AppletApplication Client J2EE Server Web ComponentBusiness Component DBMS, Enterprise Information System (EIS)27Sadegh AliakbaryJavaEE

Web Client Web pages containing various types of markuplanguage (e.g. HTML, XML), which are generatedby web components running in the web tierWeb Browseris called thin client28Sadegh AliakbaryJavaEE

Application Client It typically has a graphical user interface(GUI)created from Swing or AWT APIs, but acommand-line interface is certainly possible.Application clients directly access enterprisebeans running in the business tieris called thick client29Sadegh AliakbaryJavaEE

J2EE Server30Sadegh AliakbaryJavaEE

Java EE Java EE provides technologies (libraries) for enterpriselevel applications Java EE technologies for web applications ServletJavaServer PagesJavaServer FacesJava Enterprise BeansMany other required libraries 31Remote method invocation, Security, Database connectors,XML, Sadegh AliakbaryJavaEE

Java EE Standards and Technologies Java API for RESTful WebServices (JAX-RS)Web ServicesJava API for XML-Based WebServices (JAX-WS)Java Architecture for XMLBinding (JAXB)Java API for XML-based RPC(JAX-RPC)Java APIs for XML Messaging(JAXM)Java ServletJavaServer Faces (JSF)JavaServer Pages (JSP)32 JavaServer Pages StandardTag Library (JSTL)Enterprise JavaBeans (EJB)Java Persistence API (JPA)Java EE ConnectorArchitectureJava Message Service API(JMS)Java Transaction API (JTA)JavaMail APIJava Authentication ServiceProvider Interface forContainers (JASPIC)Java Authorization ServiceProvider Contract forContainers (JACC)Sadegh AliakbaryJavaEE

Containers Containers provide the runtime support for Java EEapplications componentsContainers provide a view of the underlying Java EEAPI to the application componentsJava EE application components never interactdirectly with each other 35They use the protocol and methods of the container forinteractingRemote Procedure Invocation (RMI)Sadegh AliakbaryJavaEE

Java EE Presentation TierComponents Client side Client can use HTML, Java Applet, Java Application, Server side Servlets are special classes to realize the requestresponse model (get, post of HTTP) JSP is a developer-friendly wrapper over the servletclasses 36External server side codeEmbed server side codeFaces & Facelets similar to JSP but uses custom tagswhich can be converted to anythingSadegh AliakbaryJavaEE

Java EE Presentation TierComponents37Sadegh AliakbaryJavaEE

Servlet A Java application run on the web server in response toHTTP GET or POST requestsServlet is used to generate dynamic content to return tobrowser: HTML, XML, Servlet is a Java program that runs as separated threadinside servlet containerServlet container is part of web server 38It interacts with web client using the request/ responseparadigmSadegh AliakbaryJavaEE

The Servlet atabase39Sadegh AliakbaryJavaEE

Servlet (cont’d) Servlet container runs servlets and send back their outputto web clientHTML page is produced by print statementsout.println(" html "); Loaded into memory once and then called many times Performance enhancementProvides APIs for session management, access toGET/POST data, 40Sadegh AliakbaryJavaEE

Servlet Implementation Servlet container provides API for session & requestmanagement through implicit objects Session object: Session managementRequest object : Access to request fields: headers, cookies, Response object: The response object is used to build the HTTP responseWhen a request for the servlet is received, the servlet enginespawns a new thread and calls appropriate service methoddoGet: Process HTTP GET requests doPost: Process HTTP POST requests doDelete, doPut, destroy() is called by to destroy the servlet 41On web application shutdown or to release some resourcesBy default, servlets are kept alive as long as possibleSadegh AliakbaryJavaEE

The Hello World Servletpublic class HelloServlet extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out response.getWriter();out.println(" HTML \n" " HEAD TITLE Hello /TITLE /HEAD \n" " BODY \n" " H1 Hello World /H1 \n" " /BODY /HTML ");}}42Sadegh AliakbaryJavaEE

web.xml servlet43Sadegh AliakbaryJavaEE

web.xml servlet-mapping44Sadegh AliakbaryJavaEE

Servlets vs. CGI Scripts Advantages: Running a servlet doesn’t require creating a separateprocess each timeA servlet stays in memory, so it doesn’t have to bereloaded each timeUntrusted servlets can be run in a “sandbox” A secured environmentDisadvantage: 45Servlets must be in JavaCGI scripts can be in any languageSadegh AliakbaryJavaEE

JavaServer Pages (JSP) JavaServer Pages technology is an extension of servlet It is the embed version of servlet in HTML JSPs are easier to develop than servletsIt runs on the web server tierContains some static HTML and some JSP tags in .jspfile, Java code inside the tags creates dynamic content(similar to PHP)When JSP is run, it creates a servlet46Sadegh AliakbaryJavaEE

JSP Example html xmlns "http://www.w3.org/1999/xhtml" head title Processing "get" requests with data /title /head body % // begin scriptletString name request.getParameter("firstName");if ( name ! null ) {% h1 Hello % name % , br / Welcome to JavaServer Pages! h1 % // continue scriptlet}else {% form action "welcome.jsp" method "get" p Type your first name and press Submit /p p input type "text" name "firstName" / input type "submit" value "Submit" / /p /form % // continue scriptlet} // end else% /body /html 47Sadegh AliakbaryJavaEE

JSP Invocation48Sadegh AliakbaryJavaEE

JSP Advantages Performance Runtime characteristics of servletServer side complex processingProgramming 49Easier to developAutomatic recompilation of modified pagesMore natural way to dynamic web pagesSadegh AliakbaryJavaEE

JSP in Summary In comparison to interpreted scripts (e.g., PHP) JSP is compiled Compiled servlet is in memory Better performanceConverted to Servlet (a complete Java program) 50More safety & better performanceFull OOP!!More complex logic implementationSadegh AliakbaryJavaEE

JavaServer Faces A user interface framework for building web applicationsJavaServer Faces Components A GUI component framework A set of custom markup tags h:form , h:head A flexible model for rendering components in different kindsof HTML or different markup 51A Renderer object generates the markup to render the component &view its dataA standard RenderKit for generating HTML/4.01Sadegh AliakbaryJavaEE

JavaServer Faces Components Backing beans The logic of application Facelet The view of application Java classes using Java EE beansXHTML file using component tagsApplication configuration & description 52Mapping between Facelets & BeansFile organization, Sadegh AliakbaryJavaEE

EJB EJBs are distributed components used to implementbusiness logic (no UI)Developer concentrates on business logic Availability, scalability, security, interoperability and handled by the J2EE serverClient of EJBs can be JSPs, servlets, other EJBs andexternal applicationsClients see interfaces53Sadegh AliakbaryJavaEE

EJB Types Session Beans Entity Beans Synchronous Action: Process oriented service providersExample: Credit AuthorizationData: Represent dataExample: Customer, AccountMessage-Driven 54Asynchronous Action: Never called directly, only receivemessagesJMSExample: Transaction loggingSadegh AliakbaryJavaEE

Java EE Summary56Sadegh AliakbaryJavaEE

MVC What is design pattern? Designing complex SW system is really difficultDesign patterns help us to design in methodological mannerModel-View-Controller (MVC) 57Model Contains data, system state, and logicView Presents data and system stateController Handles events/requests affecting model or viewSadegh AliakbaryJavaEE

MVC?!58Sadegh AliakbaryJavaEE

MVC Interactions (cont’d)modelcontroller updatesmodelview queries modelmodel signals changesviewcontroller updatesviewcontrollereventevent is passed to the controller59Sadegh AliakbaryJavaEE

MVC in Web Applications Model consists of data and system stateDatabase tables Persistent dataCurrent system state dataBusiness logic (eCommerce) 60Rules governing the transactionSadegh AliakbaryJavaEE

MVC in Web Applications (cont’d) View gives a presentation of the modelClient-side presentation in a browser window (D)HTMLCSS style-sheetsServer-side templatesAdministrative information 61Server output logsSadegh AliakbaryJavaEE

MVC in Web Applications (cont’d) Controller handles eventsUser-generated events Client-side scriptingHTTP request processingRedirectionPre-processing62Sadegh Aliakbary JavaEE

MVC in Java EE: Approach 1 The pure JSP approachSeparate JSP pages are used for the controller andthe viewBeans being used for the model partThis is a good approach when the development isheavy in graphic designers and light in JavaprogrammersRelatively complex applications can be constructedwith the use of only JSP 63Is also well suited for prototyping Web applicationsSadegh AliakbaryJavaEE

MVC in Java EE: Approach 2 A combination of servlets, JSP, and beansA servlet accepts requests and implementbusiness logic The servlet that receives requests can use other servletsto handle various kinds of requestsBeans store and perform basic data manipulationJSP implements the user views of results ofrequestsConclude: Use servlets to implement the controller JSP to implement the view64Sadegh AliakbaryJavaEE

Application Server vs. Servlet Container A servlet-container supports only the servlet API including JSP, JSTLe.g. Apache TomcatAn application server supports the whole JavaEE 65EJB, JMS, JTA, Servlets, etc.E.g. JBossSadegh AliakbaryJavaEE

Servlet Containers Apache Tomcat Jetty 66Eclipse foundationSadegh AliakbaryJavaEE

Application Servers Apache Geronimo JBoss BEA OracleGlassGish An embedded Apache TomcatJBoss, Red HatWebLogic Tomcat or Jetty as the servlet containerSun OracleThe reference implementation of Java EEA derivative of Apache Tomcat as the servlet containerWebsphere 67IBMSadegh AliakbaryJavaEE

Oracle, BEA, Sun, 68Sadegh AliakbaryJavaEE

A closer look at JSP and Servlet(more practical)69Sadegh AliakbaryJavaEE

JSP Scripting Elements There are four types of scripting elements defined 70DeclarationExpressionScriptletsCommentsSadegh AliakbaryJavaEE

DeclarationDeclares a variable or method valid in the scripting languageused in the JSP pageJSP Syntax %! declaration; [ declaration; ] . % Examples %! int i 0; % %! int a, b, c; % %! Circle a new Circle(2.0); % 71Sadegh AliakbaryJavaEE

ExpressionJSP Syntax % expression % DescriptionAn expression that is converted to a StringExampleWelcome, % userName% Output:Welcome, James72Sadegh AliakbaryJavaEE

Expression % new java.util.Date()% The resulting servlet code will probably look like this:out.print(new java.util.Date());73Sadegh AliakbaryJavaEE

Script lets Contains a code fragment valid in the page scripting languageScriptlets allows you to include a series of java statementsyou must terminate them with semicolon.JSP Syntax % code fragment % 74Sadegh AliakbaryJavaEE

Scriptlets Examples % String name null;if (request.getParameter("name") null) { % %@ include file "error.html" % % }else }% 75Sadegh AliakbaryJavaEE

CommentsTo denote any lines you want to be completely ignored bythe JSP translation process.Example %-- Author: James Gosling --% 76Sadegh AliakbaryJavaEE

taglib directive The taglib directiveDeclares that the JSP page uses custom tagsNames the tag library that defines themand specifies their tag prefix.Defines a tag library and prefix for the custom tags used in the JSPpage.JSP Syntax %@ taglib {uri "URI" tagdir "/WEB-INF/tags[/subdir] "}prefix "tagPrefix" % Examples %@ taglib uri "http://www.jspcentral.com/tags" prefix "public" % public:loop 77. /public:loop Sadegh AliakbaryJavaEE

JSP Implicit objects Implicit objects are being created by JSP mechanismautomatically.They are accessible from the JSP pages :request – represents the HTTP request, which is beingserviced by the JSP page; it is an instance of a class,implementing javax.servlet.http.httpServletRequest interface; getParameter (only strings)getAttribute & setAttribute (any objects)response – represents the HTTP response, receiving by theJSP page; it is an instance of a class, implementingjavax.servlet.http.httpServletResponse interface;78Sadegh AliakbaryJavaEE

JSP Implicit objects (cont.) session – an instance of javax.servlet.http.HttpSession,representint an HTTP session; getAttribute & setAttribute (any objects)application – represents the servlet context for the Webapplication; it is instance of javax.servlet.ServletContextclass; getAttribute & setAttribute (any objects)out – instance of javax.servlet.jsp.JspWriter class, which isbeing used to write content in the JSP output;79Sadegh AliakbaryJavaEE

Example %Integer userviews views null)userviews 0;session.setAttribute("userviews", userviews);% HTML BODY Number of User Views: % userviews% /BODY /HTML 80Sadegh AliakbaryJavaEE

Example %Integer usersview usersview null)usersview 0;application.setAttribute("usersview", usersview);% HTML BODY Number of Users Views: % usersview% /BODY /HTML 81Sadegh AliakbaryJavaEE

Example %request.setAttribute("result",new Double(5.5));% 3.jsp jsp:forward page "display.jsp" / %display.jspDouble number (Double)request.getAttribute("result");String param request.getParameter("query");% HTML BODY Computed Result: % number% Query Parameter: % param% /BODY /HTML Entering:http://localhost:8080/app1/3.jsp?query salaResults:82Sadegh AliakbaryJavaEE

Example %request.setAttribute("result",new 4.jsp% %display.jspDouble number (Double)request.getAttribute("result");String param request.getParameter("query");% HTML BODY Computed Result: % number% Query Parameter: % param% /BODY /HTML Entering:http://localhost:8080/app1/4.jsp?query salaResults:83Sadegh AliakbaryJavaEE

New Presentation-layer Technologies Nowadays, enterprise applications usually use othertechnologies in presentation layerJSF, GWT, Wicket, SpringMVC, Vaadin, But we should know the architecture of JSP/ServletsMany technologies are built on servletServlet concepts are still important and useful84Sadegh AliakbaryJavaEE

Exercise Write a simple JSP fileDeploy it on TomcatSee how it worksSee the translated ServletSee the tomcat folders and files85Sadegh AliakbaryJavaEE

Review some concepts Request/Response t.setAttribute() Session/Application (ServletContext) Why?!Forwarding requestsShare 86Sadegh AliakbaryJavaEE

Getting Information FromRequestsParameters used to convey information between clients andservletsString bookId request.getParameter("Add");Object-valued attributes 87used to pass information between the servlet containerand a servlet or between collaborating bject identifier request.getAttribute(“id”);Sadegh AliakbaryJavaEE

Getting Information FromRequests (cont)Information aboutthe protocolThe method (get, put, )Request pathHeadersQuery String 88Sadegh AliakbaryJavaEE

Constructing ResponsesIndicate the content type response.setContentType("text/html");Indicate whether to buffer output By default, any content written to the output stream is immediatelysent to the clientresponse.setBufferSize(8192);Retrieve an output stream To send character data, use the PrintWriter returned by theresponse's getWriter methodTo send binary data in a MIME body response, use theServletOutputStream returned by getOutputStreamUsing Output stream 89output.println(" html “);Sadegh AliakbaryJavaEE

Invoking Other Web ResourcesTo invoke a resource available on the server that isrunning a web component, you must first obtain aRequestDispatcher using thegetRequestDispatcher("URL") methodTo include another resource, invoke the includemethod of a RequestDispatcher: include(request, response);To forward to another resource, invoke the forward: 90forward(request, response);Sadegh AliakbaryJavaEE

Example: Transferring Control toAnother Web Componentpublic class Dispatcher extends HttpServlet {public void doGet(HttpServletRequest request,HttpServletResponse response) {.request.setAttribute("avg", new Double(18.5));RequestDispatcher dispatcher request.getRequestDispatcher("/template.jsp");if (dispatcher ! null)dispatcher.forward(request, response);}public void doPost(HttpServletRequest request,.}91Sadegh AliakbaryJavaEE

Web ContextThe application object in JSP is called theServletContext object in a servletThe context in which web components execute is anobject that implements the ServletContext interfaceWe can retrieve the web context with thegetServletContext() methodpublic class MyServlet extends HttpServlet{private ServletContext ctx null;@Overridepublic void init(ServletConfig config) throws ServletException {ctx config.getServletContext();} 92Sadegh AliakbaryJavaEE

Session: Maintaining Client StateSessions are represented by an HttpSession objectYou can access a session by calling the getSession()method of a request objectHttpSession session , obj);93Sadegh AliakbaryJavaEE

Servlet Container Folder Structure bin conf startupserver.xmlliblogstempwebappswork94War filesSadegh AliakbaryJavaEE

A web-app Structure Html, css, js, JSPsWEB-INF 95web.xmlclasseslibSadegh AliakbaryJavaEE

web.xml An xml fileContains 96Servlet definitionsServlet-mappingsFilter definitionsFilter-mappingsError-pages Sadegh AliakbaryJavaEE

web.xml servlet97Sadegh AliakbaryJavaEE

web.xml servlet-mapping98Sadegh AliakbaryJavaEE

web.xml error pages 99Sadegh Aliakbary200 OK401 Unauthorized403 Forbidden404 Not FoundJavaEE

Import in JSP Import in Java Import classes: includes the mentioned class in theprogramExample: import java.util.ArrayList;import java.sql.Connection;Import in JSP: %@ page import “CLASS NAME" % Example: 100 %@ page import "java.util.List" % Sadegh AliakbaryJavaEE

Filter Acts as preprocessor to request/response for targetservletExtracts common scenario among different servletsApplications? Authentication 101SSOStatisticsLog Sadegh AliakbaryJavaEE

web.xml filter102Sadegh AliakbaryJavaEE

Filter Servlets HttpPageAuthenticateFilterServlet erifyDataServletSadegh AliakbaryJavaEE

Filter ServletImport java.io.*;import javax.servlet.*;import javax.servlet.http.*;publc class PageHits extends HttpServlet implements Filter{private FilterConfig filterConfig null;implementFilter Interfacepublic void init(FilterConfig filterConfig) throws ServletException{this.filterConfig filterConfig;}public void destroy({this.filterConfig null;}104override init. methodoverride destroy methodSadegh AliakbaryJavaEE

Filter Servlet (cont.)public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException{if (filterConfig null)return;Must overridedoFilter methodInteger counter (Integer) nter");if (counter null)counter new Integer(0);counter new Integer(counter.intValue() 1);filterConfig.getServletContext().log("Number of hits is " bute("Counter", counter);chain.doFilter(req, resp)}105Sadegh AliakbaryJavaEE

Modify Deployment Descriptor web-app filter filter-name PageHits /filter-name filter-class ir.ac.sbu.PageHits /filter-class /filter filter-mapping filter-name PageHits /filter-name url-pattern /payment/* /url-pattern /filter-mapping /web-app 106Sadegh AliakbaryJavaEE

Listener Servlet Servlet is automatically executed whensome external event occursEvent ListenersHTTPSessionActivationListenerSession is ssion attribute is added/removedHTTPSessionListenerSession attribute is rvlet contextattribute isadded/removedServletContextListenerServlet context changes107Sadegh AliakbaryJavaEE

What Events to Listen? ServletContextListener HttpSessionListener vletRequestAttributeListener Listener buteListener Sadegh AliakbaryJavaEE

Examplepublic class MyListener onEvent p) {}sessionWillPassivate(HttpSessionEvent p) {}attributeAdded(HttpSessionBindingEvent p) {}attributeRemoved(HttpSessionBindingEvent p) {}attributeReplaced(HttpSessionBindingEvent p) {}sessionCreated(HttpSessionEvent p) {}sessionDestroyed(HttpSessionEvent p) {}}109Sadegh AliakbaryJavaEE

Create Listener ServletImport java.io.*;import javax.servlet.*;import javax.servlet.http.*;publc class Listener extends HttpServlet implements ServletContextListener{private ServletContext context null;Must implementListner Interfacepublic void contextIntialized(ServletContextEvent event){context event.getServerContext();Integer counter new Integer(0);context.setAttribute(“Counter”, counter);context.log(“Created Counter”);Must overridecontextInitializedmethod}public void contextDestroyed(ServletContextEvent ��Counter”);Must overridecontextDestroyedmethod}}110Sadegh AliakbaryJavaEE

web-app servlet /servlet servlet-mapping /servlet-mapping filter Web.xml /filter filter-mapping /filter-mapping listener listener-class Listener / listener -class /listener /web-app 111Sadegh AliakbaryJavaEE

Modify Filter Servletpublic void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException{if (filterConfig null)return;synchronized (this){Integer counter ( Integer) ounter”);if (counter null)No longer neededcounter new Integer(1);counter new Integer(counter.intValue() 1);filterConfig.getServletContext().log(“Number of hits is “ bute(“Counter”, counter); counter);}chain.doFilter(request, response);}}112Sadegh AliakbaryJavaEE

Modified Filter Servletpublic void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException{if (filterConfig null)return;synchronized (this){Integer counter ( Integer) ounter”);counter new Integer(counter.intValue() 1);filterConfig.getServletContext().log(“Number of hits is “ bute(“Counter”, counter); counter);}chain.doFilter(request, response);}}113Sad

Java EE Java Platforms Java Card: Smart card version Java ME (Micro Edition): Embedded systems, e.g. Mobile handheld Java SE (Standard Edition): Desktop application development Java EE (Enterprise Edition): Enterprise distributed application software Java EE add standards and libraries to SE for fault- tolerant, distributed, multi-tier based components

Related Documents:

java.io Input and output java.lang Language support java.math Arbitrary-precision numbers java.net Networking java.nio "New" (memory-mapped) I/O java.rmi Remote method invocations java.security Security support java.sql Database support java.text Internationalized formatting of text and numbers java.time Dates, time, duration, time zones, etc.

Java Version Java FAQs 2. Java Version 2.1 Used Java Version This is how you find your Java version: Start the Control Panel Java General About. 2.2 Checking Java Version Check Java version on https://www.java.com/de/download/installed.jsp. 2.3 Switching on Java Console Start Control Panel Java Advanced. The following window appears:

3. _ is a software that interprets Java bytecode. a. Java virtual machine b. Java compiler c. Java debugger d. Java API 4. Which of the following is true? a. Java uses only interpreter b. Java uses only compiler. c. Java uses both interpreter and compiler. d. None of the above. 5. A Java file with

CORE JAVA TRAINING COURSE CONTENT SECTION 1 : INTRODUCTION Introduction about Programming Language Paradigms Why Java? Flavors of Java. Java Designing Goal. Role of Java Programmer in Industry Features of Java Language. Installing Java Di

Java Platform, Enterprise Edition (Java EE) is the industry-standard platform for building enterprise-class applications coded in the Java programming language. Based on the solid foundation of Java Platform, Standard Edition (Java SE), Java EE adds libraries and system services that support the scalability, accessibility, security,

besteht aus der Java-API (Java Application Programming Interface) und der Java-VM (Java Virtual Machine). Abbildung 1: Java-Plattform Die Java-API ist eine große Sammlung von Java-Programmen, die in sog. Pakete (packages) aufgeteilt sind. Pakete sind vergleichbar mit Bibliotheken in anderen Programmiersprachen und umfassen u.a.

JAR Javadoc Java Language jar Security Others Toolkits: FX Java 2D Sound . Java Programming -Week 1. 6/25. Outline Java is. Let’s get started! The JDK The Java Sandbox . into your namespace. java.lang contains the most basic classes in the Java language. It is imported automatically, so

The publication of the ISO 14001 standard for environmental managements systems (EMS) in 1996 and then revised in 2004 has proved to be very successful, as it is now implemented in more than 159 countries and has provided organizations with a powerful management tool to improve their environmental performance. More than 223 149 organizations have been certified worldwide against ISO 14001 at .