What Are Java EE Containers
What Are Java EE Containers
Ans
Definition (1 mark): Java EE containers are runtime environments within the Java EE
architecture that host and manage the execution of enterprise-level Java applications. There
are two main types of containers: the EJB container for Enterprise JavaBeans components
and the web container for servlets and JSP (JavaServer Pages).
EJB Container (Enterprise JavaBeans Container):
Manages Enterprise JavaBeans components, providing services like lifecycle
management, transaction management, security, and persistence.
Essential for building scalable and distributed enterprise applications.
Web Container (Servlet Container):
Manages the execution of web-based components such as servlets and
JavaServer Pages (JSP).
Offers services like lifecycle management, multithreading, and session
management for web components.
Servlets handle HTTP requests and responses, while JSP allows the embedding
of Java code within HTML pages.
Application Client Container:
Manages the execution of Java EE application client components.
Provides services for application clients to interact with enterprise resources.
Enables the development of Java EE applications with client-side components
that run on the client machine.
Applet Container:
Handles the execution of Java applets, which are small, client-side Java
programs embedded in web pages.
Provides a secure and controlled environment for running Java applets within
a web browser.
Applets were popular in the early days of web development for creating
interactive content.
These four containers play distinct roles within the Java EE architecture, catering to
different types of components and facilitating the development of diverse enterprise
applications. If you have any more questions or if there's anything specific you'd like
to explore further, feel free to let me know!
Method Description
public void init(ServletConfig config) initializes the servlet. It is the life cycle
method of servlet and invoked by the
web container only once.
The classloader is responsible to load the servlet class. The servlet class is loaded
when the first request for the servlet is received by the web container.
Oracle does not support the JDBC-ODBC Bridge from Java 8. Oracle recommends
that you use JDBC drivers provided by the vendor of your database instead of the
JDBC-ODBC Bridge.
Advantages:
easy to use.
can be easily connected to any database.
Disadvantages:
Performance degraded because JDBC method call is converted into the ODBC function calls.
The ODBC driver needs to be installed on the client machine.
2) Native-API driver
The Native API driver uses the client-side libraries of the database. The driver converts JDBC
method calls into native calls of the database API. It is not written entirely in java.
Advantage:
performance upgraded than JDBC-ODBC bridge driver.
Disadvantage:
The Native driver needs to be installed on the each client machine.
The Vendor client library needs to be installed on client machine.
Disadvantages:
Network support is required on client machine.
Requires database-specific coding to be done in the middle tier.
Maintenance of Network Protocol driver becomes costly because it requires database-
specific coding to be done in the middle tier.
4) Thin driver
The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it
is known as thin driver. It is fully written in Java language.
Advantage:
Better performance than all other drivers.
No software is required at client side or server side.
Disadvantage:
Drivers depend on the Database.
Advantages Disadvantages
The keyword used to create a class is The keyword used to create an interface is
“class” “interface”
A class can be instantiated i.e., objects An Interface cannot be instantiated i.e. objects
of a class can be created. cannot be created.
For adding cookie or getting the value from the cookie, we need some methods
provided by other interfaces. They are:
1. public void addCookie(Cookie ck):method of HttpServletResponse interface is
used to add cookie in response object.
2. public Cookie[] getCookies():method of HttpServletRequest interface is used
to return all the cookies from the browser.
URL URI
URL provides the details about what type of protocol is URI doesn’t contains the
to be used. protocol specification.
It comprises of scheme,
It comprises of protocol, domain, path, hash, and so on. authority, path, query and
many more.
index.html
1. <html>
2. <body>
3. <form action="go" method="post" enctype="multipart/form-data">
4. Select File:<input type="file" name="fname"/><br/>
5. <input type="submit" value="upload"/>
6. </form>
7. </body>
8. </html>
UploadServlet.java
1. import java.io.*;
2. import javax.servlet.ServletException;
3. import javax.servlet.http.*;
4. import com.oreilly.servlet.MultipartRequest;
5.
6. public class UploadServlet extends HttpServlet {
7.
8. public void doPost(HttpServletRequest request, HttpServletResponse response)
9. throws ServletException, IOException {
10.
11. response.setContentType("text/html");
12. PrintWriter out = response.getWriter();
13.
14. MultipartRequest m=new MultipartRequest(request,"d:/new");
15. out.print("successfully uploaded");
16. }
17. }
There are two arguments passed in MultipartRequest class constructor, first one is
HttpServletRequest object and second one is String object (for location). Here I am
supposing that you have new folder in D driver.
web.xml file
1. <web-app>
2.
3. <servlet>
4. <servlet-name>UploadServlet</servlet-name>
5. <servlet-class>UploadServlet</servlet-class>
6. </servlet>
7.
8. <servlet-mapping>
9. <servlet-name>UploadServlet</servlet-name>
10. <url-pattern>/go</url-pattern>
11. </servlet-mapping>
12.
13. </web-app>