Beruflich Dokumente
Kultur Dokumente
ER/CORP/CRS/ED113/003
Confidential
General Guideline
(2008) Infosys Technologies Ltd. This document contains valuable confidential and proprietary information of Infosys. Such confidential and proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and commercialized. Such information is furnished herein for training purposes only. Except with the express prior written permission of Infosys, this document and the information contained herein may not be published, disclosed, or used for any other purpose.
Confidential
Confidential Information
This Document is confidential to Infosys Technologies Limited. This document contains information and data that Infosys considers confidential and proprietary (Confidential Information). Confidential Information includes, but is not limited to, the following:
Corporate and Infrastructure information about Infosys Infosys project management and quality processes Project experiences provided included as illustrative case studies
Any disclosure of Confidential Information to, or use of it by a third party, will be damaging to Infosys. Ownership of all Infosys Confidential Information, no matter in what media it resides, remains with Infosys. Confidential information in this document shall not be disclosed, duplicated or used in whole or in part for any purpose other than reading without specific written permission of an authorized representative of Infosys. This document also contains third party confidential and proprietary information. Such third party information has been included by Infosys after receiving due written permissions and authorizations from the party/ies. Such third party confidential and proprietary information shall not be disclosed, duplicated or used in whole or in part for any purpose other than reading without specific written permission of an authorized representative of Infosys.
Copyright 2008, Infosys Technologies Ltd.
Confidential
Learning approach
The following are strongly suggested for a better learning and understanding of this course: Noting down the key concepts in the class, explained by the educator Analyze all the examples / code snippets provided Study and understand the self study topics Completion and submission of all the assignments, on time Completion of the self review questions in the lab guide Study and understand all the artifacts including the reference materials / elearning / supplementary materials specified Completion of the project (if applicable for this course) on time inclusive of individual and group activities Taking part in the self assessment activities Participation in the doubt clearing sessions
Confidential
Course Objectives
To illustrate the Enterprise Application development and web application development scenario To facilitate learning of Java technologies such as Servlet, JSP and JSF for developing presentation tier for web application To illustrate role and usage of web container in web application deployment To illustrate deployment of web application on Application Server To share the best practices in web application development
Copyright 2008, Infosys Technologies Ltd.
Confidential
Course Pre-requisites
Knowledge of
HTML Forms development HTTP Methods HTTP Request and Response model Core Java concepts such as packaged class, interfaces and API Advanced Java concepts such as multithreading, connecting to database
Confidential
What is Presentation tier using JSP and JSF and where it is being used?
Every big business application is divided in various tiers Code logic which takes care of generating the user interface for accepting input or displaying output is called Presentation logic This course has relevance as, it helps you build presentation logic for web applications using Java technologies like JSP and Servlet
Confidential
Expectations
At the end of this course, the participant should be able to Identify the requirements of enterprise application development as well as web application development Design and write Servlet and JSPs (using various tags and EL) Design and develop web application using JSF-enabled JSPs in Eclipse IDE, given the problem definition Develop web application that supports i18n Deploy the developed web application in an application server such as JBoss 5.0 Test and Debug the JSPs in web application
Copyright 2008, Infosys Technologies Ltd.
Confidential
Course Agenda
Day 1
Recap of Enterprise Application development Application Server concepts Servlet Model and lifecycle Deployment of Servlets
Day 2
Introduction to JSP Basic tags in JSP Lifecycle and lifecycle methods of JSP Implicit objects in JSP Tags in JSP Directive Elements in JSP Action Elements in JSP
Copyright 2008, Infosys Technologies Ltd.
Confidential
Course Agenda
Day 3
JSTL and Expression Language Model 1 and Model 2 architecture Developing web application using MVC architecture Introduction to frameworks and JSF Developing and deploying web application using JSF
JSF Concepts overview UI Components and Core tags in JSF Managed Bean Facility Event Handling Page Navigation
Copyright 2008, Infosys Technologies Ltd.
Day 4
10
Confidential
Course Agenda
Day 5
Validators Converters Dynamic Data Table Creation Internationalization and localization application JSF Request Processing Lifecycle
of
JSF
web
Day 6-8
Project
Copyright 2008, Infosys Technologies Ltd.
11
Confidential
12
Confidential
13
Confidential
ER/CORP/CRS/ED113/003
Confidential Confidential
15
Confidential
16
Confidential
17
Confidential
ER/CORP/CRS/ED113/003
Confidential Confidential
23
Confidential
29
Confidential
For delivery of static page, all we For delivery of dynamic page, apart require is web server and, already- from Web Server, we require helper stored HTML files in it program to generate dynamic content
The program / software component that executes the serverside program to generate the dynamic content is known as the Web Container
Copyright 2008, Infosys Technologies Ltd.
30
Confidential
31
Confidential
ER/CORP/CRS/ED113/003
Confidential Confidential
33
Confidential
Servlets
The Container should be able to execute any Servlet This requirement calls for a standard interface for all the Servlets So, in order to become a servlet, that class should implement the interface called Servlet in the package javax.servlet Servlets are managed by Servlet container
Copyright 2008, Infosys Technologies Ltd.
34
Confidential
Servlet API
Present in package javax.servlet
Servlet Interface init() called once for initialization of instance variables of instantiated servlet object service()- called each time, servlet is requested destroy() - called once after servlet object is removed Request Handling methods
35
Confidential
Servlet
(present in javax.servlet)
GenericServlet
(present in javax.servlet)
HttpServlet
(present in javax.servlet.http)
36
Confidential
37
Confidential
Contd
out.println(headerString+ "<BODY BGCOLOR=\"#FDF5E6\">\n <H1>Hello World! Welcome to Servlets!!!</H1></BODY></HTML>"); } //Override remaining methods
public void destroy() { }
public class HelloServlet implements Servlet { public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String headerString = "<HTML><HEAD><TITLE> Servlet world </TITLE> </HEAD>"
Copyright 2008, Infosys Technologies Ltd.
Confidential
web.xml
<! XML file header tag declarations --> <servlet> <servlet-name>myFirstServlet </servlet-name> <servlet-class> edu.infy.servlets.HelloServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>myFirstServlet </servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping> <!-- end of root tag -->
39
Confidential
WEB-INF
welcome.html
src
classes
edu servlets
lib
web.xml
infy
HelloServlet.java
40 Confidential
Make it Run
Deploy it on the web container (tomcat) Start the server Open Internet Explorer -> Type the URL for the html resource http://localhost:8080/ServletDemos/welcome.html Click on the link given Watch for the output Look at the URL
41
Confidential
42
Confidential
43
Confidential
Application Server
Application Servers are specialized Web Server + Web Container + EJB Container Application Servers provide all the system services to address non-functional requirements :
Scalability through resource pooling Security Transaction management Performance- connection pooling
Application developers can concentrate on functional requirements by coding required business logic
Copyright 2008, Infosys Technologies Ltd.
44
Confidential
JBoss is open source, under LGPL Full-fledged App Server built on J2EE 1.4 spec Comes in 3 flavors: all, minimal and default
Copyright 2008, Infosys Technologies Ltd.
45
Confidential
Servlet Lifecycle
Web Container (1) Load class HelloServlet Servlet Class in memory
(4) Client makes request to the servlet: service() (3) Initialize: init() HelloServlet
Servlet Object (5) Destruction: After destruction, destroy() in memory Servlet Object destroyed
Copyright 2008, Infosys Technologies Ltd.
46
Confidential
47
Confidential
48
Confidential
49
Confidential
50
Confidential
51
Confidential
loginForm.html
loginForm.html
<html><head> <title>Login Page</title> </head> <body bgcolor="#CCFFCC" > <form action="Login" method="post"> <h2><center>Enter Login Details </center> <br> <table border="4" align="center" bordercolor="brown" bgcolor="pink"> <tr><td>UserName</td><td> <input type="text" name="username"> </td></tr>
loginForm.html
<tr><td><input type="submit" value="Login"/></td> <td><input type="reset" value="Reset"/></td></tr> </table> </h2> </form> </body> </html>
52
Confidential
LoginServlet.java (1/2)
LoginServlet.java
package edu.infy.servlets; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; /imports from javax.servlet package are done //here public class LoginServlet extends HttpServlet{ String message; protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { message = new String(); String username = request.getParameter("username");
Copyright 2008, Infosys Technologies Ltd.
LoginServlet.java
if((username == null) || (username.length()==0)){ message="Username required field; }else{ if(username.equals(admin){ message=Welcome! Login successful!;
53
}else{ message=Sorry guest, Login failed!!!; } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML><HEAD><TITLE>Login Page</TITLE></HEAD><BODY BGCOLOR=\"#99CCFF\>" + "<H1> "+ message+" </H1></BODY> </HTML>"); }Confidential
web.xml
55
Confidential
Result
56
Confidential
Server-side validations
What if data for username and password are left blank and form is submitted? How will you make sure that user has entered all mandatory fields on the form before submitting it? Answer JavaScript But this is client-side validations, and user can disable JavaScript from the web browser settings So, we need to check it at server-side too Checking whether the data given for the parameter is zero-length or null are must Server-side validations
Copyright 2008, Infosys Technologies Ltd.
57
Confidential
We need a technology which helps us to write/maintain server-side presentation logic easily. JSP!!!
Copyright 2008, Infosys Technologies Ltd.
58
Confidential
In which file do you associate a servlet with the URL? In web.xml, using <servlet-mapping> element The web container receives 10 requests for a HelloWorld servlet. How many instances of HelloWorld servlet will be created by the Container?
Only One instance
Copyright 2008, Infosys Technologies Ltd.
59
Confidential
60
Confidential
Reference Material
For more information about the topics covered today, refer the supplementary material given in the following link: http://myshec123505d/EBook
61
Confidential
Summary
Java Platform, Enterprise Edition (Java EE) is the industry, open standard for developing portable, robust, scalable and secure server-side Java applications A Java EE App Server takes care of the nonfunctional requirements of a Java EE application Java EE provides two technologies Servlet and JSP to develop the server side presentation logic As a good programming practice, presentation logic and business logic need to be separated
Copyright 2008, Infosys Technologies Ltd.
62
Confidential
Summary
Servlets are difficult to maintain by the page authors/ web designers Web designers would be maintaining the presentation logic and hence Sun Microsystems offered JSP technology which is as simple as HTML and as powerful as Servlets
63
Confidential
Thank You
The contents of this document are proprietary and confidential to Infosys Technologies Ltd. and may not be disclosed in whole or in part at any time, to any third party without the prior written consent of Infosys Technologies Ltd. 2008 Infosys Technologies Ltd. All rights reserved. Copyright in the whole and any part of this document belongs to Infosys Technologies Ltd. This work may not be used, sold, transferred, adapted, abridged, copied or reproduced in whole or in part, in any manner or form, or in any media, without the prior written consent of Infosys Technologies Ltd.
64
Confidential
65
Confidential
Application Root
WEB-INF
web.xml
src
Packaged servlets
66
Confidential