What is J2EE?
J2EE is an environment for developing and deploying enterprise applications.The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols that provide the functionality for developing multitiered, web-based applications.
What is a Servlet?
A Servlet is a Java object that is based on Servlet framework and extends the functionality of a web server, being responsible for creating dynamic contents.
Which tier do Servlet and JSP components belong to?
Servlet and JSP are web tier components that run in a web tier container.
What roles do Servlet and JSP play?
• receive client requests (HTTP)
• perform business logic
• return responses to clients
What are the advantages of Servlet Technology?
• Abundant third-party tools and web servers support Servlet
• Access to an entire family of Java APIs
• Reliable, reusability, scalability
• Platform and server independent
• Secure
• Automatic reloading of Servlets
What is JSP Technology?
• Enables separation of business logic (Java Beans or custom tags) from presentation (HTML or XML/XSLT)
• Extensible via custom tags
• Builds on Servlet technology
What advantage does JSP have over Servlet technology? What is the downside to Servlet?
The downside to Servlet is that the presentation (HTML pages) has to be generated as part of the Servlet Java code, i.e. using printf statements, therefore whenever changes are made to the presentation, the Java code has to be changed and recompiled, redeployed. This in turn results in a maintenance problem of your application along with making web-page prototyping very difficult.
What is JSP page?
A text-based document capable of returning dynamic content to a client browser, which contains both Static (HTML, XML) and Dynamic content (programming code, JavaBeans, custom tags).
When to use Servlet over JSP?
• Extend the functionality of a Web server such as supporting a new file format
• Generate objects that do not contain HTML (graphics or charts)
• Avoid returning HTML directly from your Servlets whenever possible
Should I use Servlet or JSP?
In practice Servlets and JSP are used together via MVC (Model, View, Controller) architecture. Servlet handles Controller while JSP handles View. Servlet is good for controlling functionality while JSP is good for handling presentation logic.
What is a request?
Information that is sent from a client to a server. The information consists of (1) who made the request (2) user-entered data and (3) HTTP header entries.
What is a response?
Information that is sent to a client from a server. The information consists of static text (HTML, plain) or binary(image) data. It also contains HTTP response headers and cookies which are used to maintain session state.
What does the HTTP request contain?
It contains a header, a method(Get, Post, Put, Header) and request data.
What does the Get request contain?
User entered information is appended to the URL in a query string and can only send limited amount of data. i.e. ../servlet/ViewCourse?FirstName=Tom&LastName=Flewwelling
What does the Post request contain?
User entered information is sent as data (not appended to the URL). Any amount of data can be sent.
Servlet Interfaces and classes
List the interfaces and classes associated with Servlet.
Classes: HttpSession, GenericServlet, HttpServlet
Interfaces: Servlet, ServletRequest, HttpServletRequest, ServletResponse, HttpServletResponse
Servlet Life-Cycle
What controls the life cycle of a Servlet?
The container.
Explain the life cycle of a Servlet.
The init() gets called once a Servlet instance is created. The service() gets called every time there comes a new request. The service() calls doGet() and doPost() for incoming HTTP requests. Finally the destroy() is called to remove the Servlet instance.
What classes are Servlet defined in?
javax.servlet.GenericServlet or javax.servlet.HttpServlet.
Is the service() abstract? If so explain.
Yes, the service() is abstract and GenericServlet is thus abstract class. Therefore the service() of the GenericServlet class has to be implemented by a subclass – HTTPServlet class.
What role does the init() play?
Invoked once when the Servlet is instantiated and performs any set-up. i.e. Setting up a data base connection.
What role does the destroy() play?
Invoked before Servlet instance is removed and performs any clean up. i.e. Closing a database connection.
How are user entered parameters via the browser accessed?
They are accessed via getParameter().
How are init parameters via the web.xml deployment descriptor file accessed?
They are accessed via getInitParameter().
What kind of requests and responses does the service() receive?
It receives generic requests and responses. i.e. service(ServletRequest request, ServletResponse response).
What kind of requests and responses do the doGet() and doPost() receive?
They receive HTTP requests and responses. i.e. doGet(HTTPServletRequest request, HTTPServletResponse response), doPost(HTTPServletRequest request, HTTPServletResponse response).
Note: The doGet() and doPost() methods of HTTPServlet class are invoked from concrete implementation of service() method in the HTTPServlet class.
What are 5 things you want to do in doGet() and doPost() methods?
1.Extract client sent info such as user-entered parameter values that were sent as query string.
2.Set and get attributes to and from scope objects.
3.Perform some business logic or access the database.
4.Optionally include or forward your request to other web components.
5.Populate HTTP response message and then send it to client.
What are the typical steps to follow when creating a HTTP response?
1.Fill HTTP response headers with content type.
2.Set properties such as buffer size.
3.Get an output stream object from the response object and the write body contents to the output stream.
What are Scope Objects?
Scope Objects enable sharing information among collaborating web components (Servlet & JSP) via attributes(name/object pairs) maintained in Scope Objects.
What methods are used to access the attributes maintain in the Scope Objects?
getAttribute() & setAttribute()
Name 4 different types of Scope Objects: Class
Web context: Accessible from Web components within a Web context
Session: Accessible from Web components handling a request that belongs to the session
Request: Accessible from Web components handling the request
Page: Accessible from JSP page that creates the object
Web Context
How is a web context object represented?
A web context object is represented by ServletContext object. There is one ServletContext object per web application.
What is ServletContext used for?
It is used by servlets to:
• Set and get context-wide (application-wide) object-valued attributes
• Get request dispatcher
• Access Web content-wide initialization parameters set in the web.xml file
• Access Web resources associated with the Web context
• Log
• Access other misc. info
How do you access ServletContext object?
Call getServletContext() from within your servlet code and filter. Also, the ServletContext is located in ServletConfig object, which the Web server provides to a servlet when the servlet is initialized.
Session (Http Session)
Why is HTTPSession important?
It’s a mechanism employed to maintain client state across a series of requests from a same user over some period of time. i.e. Online shopping cart. Since HTTP is stateless, the HttpSession maintains client state in the form of attributes and the attributes remain in the session scope.
How do you get HTTPSession object in your Servlet code?
By an HTTPRequest object that is passed to your servlet object as an input parameter of Service() or getSession().
Servlet Request (HttpServletRequest)
What is a Servlet Request?
It contains data passed from client to server and implements ServletRequest.
How do you get client sent(user-entered) parameters?
By HTTP GET and HTTP POST.
HTTP GET: The name and value pairs of the parameters are sent as appendix to the URL.
HTTP POST: The name and value pairs of the parameters are sent as user data.
How to extract the values of the parameters?
getParameter() from the ServletRequest interface.
How are object/values attributes set?
The Servlet container itself can set attributes to make available custom information about a request. Or the Servlet set application-specific attribute. i.e. void setAttribute(java.lang.String name, java.lang.Object o)
How can Servlets get client information from the request?
String request.getRemoteAddr(); - get client’s IP address
String request.getRemoteHost(); - get client’s host name
How to obtain Server information?
String request.getServerName(); i.e. www.sun.com
int request.getServerPort(); i.e. Port number 8080
How to determine if the line is secure (if HTTPS)?
boolean isSecure()
HTTPServletRequest
What is HTTP Servlet Request?
It contains data passed from HTTP client to HTTP Servlet that is created by Servlet container and passed to Servlet as a parameter of doGet() or doPost().
What does a HTTP Request URL contain?
http://[host]:[port]/[request path]?[query string]
What do HTTP Request Headers do?
They Accept, Accept-Encoding and Authorize.
HTTPServletResponse
What is a Servlet Response?
It contains data passed from the Servlet to the client. And all Servlet responses implement ServletResponse Java Interface, which contains methods for retrieving an output stream, indicating content type, indicating whether to buffer output or not, for setting localization information.
Status Code in HTTPResponse
Why do we need HTTP response status code?
• To forward a client to another page.
• Indicate resources are missing.
• Instruct browser to use cached copy.
List some common Status Codes?
• 200(SC_OK) Success and documents follows – default for all Servlets.
• 204(SC_No_CONTENT) Success but no response body
• 301(SC_MOVED_PERMANENTLY) The document moved permanently (indicated in Location header)
Header in HTTPResponse
Why HTTP Response Headers?
To name a few:
• Give forwarding location
• Specify cookies
• Supply the page modification date
• Instruct the browser to reload the page after a designated interval
• Give the file size so that persistent HTTP connections can be used
• Designate the type of document being generated
Body in HTTPResponse
What are the key points to writing a response Reader?
A Servlet almost always return a response body which could be either a PrintWriter or a ServletOutputStream.
Overview
What are the 4 main J2EE application parts?
Client-tier components run on the client machine.
Web-tier components run on the J2EE server.
Business-tier components run on the J2EE server.
Enterprise information system (EIS)-tier software runs on the EIS server.
What do Enterprise JavaBeans components contain?
Enterprise JavaBeans components contains Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier. All the business code is contained inside an Enterprise Bean which receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.
Are JavaBeans J2EE components?
No. JavaBeans components are not considered J2EE components by the J2EE specification. They are written to manage the data flow between an application client or applet and components running on the J2EE server or between server components and a database. JavaBeans components written for the J2EE platform have instance variables and get and set methods for accessing the data in the instance variables. JavaBeans components used in this way are typically simple in design and implementation, but should conform to the naming and design conventions outlined in the JavaBeans component architecture.
Is HTML page a web component?
No. Static HTML pages and applets are bundled with web components during application assembly, but are not considered web components by the J2EE specification. Even the server-side utility classes are not considered web components, either.
What can be considered as a web component?
J2EE Web components can be either servlets or JSP pages. Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.
What is the container?
Containers are the interface between a component and the low-level platform specific functionality that supports the component. Before a Web, enterprise bean, or application client component can be executed, it must be assembled into a J2EE application and deployed into its container.
What are container services?
A container is a runtime support of a system-level entity. Containers provide components with services such as:
lifecycle management
security
deployment
threading
What is deployment descriptor?
A deployment descriptor is an Extensible Markup Language (XML) text-based file with an .xml extension that describes a components deployment settings. A J2EE application and each of its modules has its own deployment descriptor. For example, an enterprise bean module deployment descriptor declares transaction attributes and security authorizations for an enterprise bean. Because deployment descriptor information is declarative, it can be changed without modifying the bean source code. At run time, the J2EE server reads the deployment descriptor and acts upon the component accordingly.
What is the EAR file?
An EAR file is a standard JAR file with an .ear extension, named from Enterprise ARchive file. A J2EE application with all of its modules is delivered in EAR file.
What is JAXP?
JAXP stands for Java API for XML. XML is a language for representing and describing text-based data which can be read and handled by any program or tool that uses XML APIs. It provides standard services to determine the type of an arbitrary piece of data, encapsulate access to it, discover the operations available on it, and create the appropriate JavaBeans component to perform those operations.
What is Java Naming and Directory Service?
The JNDI provides naming and directory functionality. It provides applications with methods for performing standard directory operations, such as associating attributes with objects and searching for objects using their attributes. Using JNDI, a J2EE application can store and retrieve any type of named Java object. Because JNDI is independent of any specific implementations, applications can use JNDI to access multiple naming and directory services, including existing naming and directory services such as LDAP, NDS, DNS, and NIS.
What is Struts?
A Web page development framework. Struts combines Java Servlets, Java Server Pages, custom tags, and message resources into a unified framework. It is a cooperative, synergistic platform, suitable for development teams, independent developers, and everyone between.
<----------------------------------------EJB----------------------------------->
The EJB container implements the EJBHome and EJBObject classes. For every request from a unique client, does the container create a separate instance of the generated EJBHome and EJBObject classes?
The EJB container maintains an instance pool. The container uses these instances for the EJB Home reference irrespective of the client request. while refering the EJB Object classes the container creates a separate instance for each client request. The instance pool maintainence is up to the implementation of the container. If the container provides one, it is available otherwise it is not mandatory for the provider to implement it. Having said that, yes most of the container providers implement the pooling functionality to increase the performance of the application server. The way it is implemented is again up to the implementer.
What is Hibernate?
Hibernate is a powerful, high performance object/relational persistence and query service. Hibernate lets you develop persistent classes following object-oriented idiom - including association, inheritance, polymorphism, composition, and collections. Hibernate allows you to express queries in its own portable SQL extension (HQL), as well as in native SQL, or with an object-oriented Criteria and Example API.
What are Struts?
The "Struts" framework tends to mainly focus on the web tier.
What is Spring Framework?
The Spring Framework tends to mainly focus on the Enterprise tier while providing support and integrating well with the Struts framework.
The "Struts" framework is no doubt a good framework to enhance the ability of the web tier, but the biggest drawback is the fact that it caters only to the web tier and leaves most of the Enterprise tier or middle tier to the fancy of the application architects. The Application architects need to provide an additional framework to deal with the enterprise tier and make sure that the new framework integrates well with the Struts framework. Spring tries to alleviate this problem by providing a comprehensive framework, which includes an MVC framework, an AOP integration framework, a JDBC integration framework, and an EJB integration framework
Wednesday, September 26, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment