In J2EE, application modules are packaged as EAR, JAR and WAR based on their functionality.
Each type of file (.jar, .war, .ear) is processed uniquely by application servers, servlet containers, EJB containers, etc
Jar file (file with a .jar extension) is the normal Java Application archive and intended to hold generic libraries of Java classes, resources, auxiliary files, etc
This can be added in classpath for compilation and to run java program. Generally in web applications we keep these files in lib directory of the application.
Ex: ojdbc14.jar – This contains all the classes to connect the oracle database
Servlet-api.jar – contains servlet related classes
Web modules which contains Servlet class files,JSP Files,supporting files, GIF and HTML files are packaged as JAR file with .war( web archive) extension
War files (files with a .war extension) are intended to contain complete Web applications. In this context, a Web application is defined as a single group of files, classes, resources, .jar files that can be packaged and accessed as one servlet context.
All above files(.jar and .war) are packaged as JAR file with .ear ( enterprise archive) extension and deployed into Application Server.
Ear files (files with a .ear extension) are intended to contain complete enterprise applications. In this context, an enterprise application is defined as a collection of .jar files, resources, classes, and multiple Web application.
Servlet is faster in execution as every jsp is changed on converted to servlet before starting the execution. Thus the server need to spend some time to convent a JSP file to servlet at it’s first time execution. But developing a jsp is very easy when compared to servlet.
Every time before executing a jsp & server searches for related servlet file. If it existsWhen ever we send a request to the JSP file it checks the servlet representing the JSP file. Then the web container runs the jsp compiler that generates the servlet code
then start the execution of that servlet otherwise server creates servlet files for those jsps first and then execution takes place
It is possible to share the same object of stateless session bean by multiple clients.
A Server maintains a pool of objects in case of stateless session bean. And every When ever we send a request to the JSP file it checks the servlet representing the JSP file. Then the web container runs the jsp compiler that generates the servlet code
time for a request it uses one of the pool of objects which is free at that time. The server gets back that object in to the pool only after the client work on that object is Directoryover [ client says that by invoking ejbremove() method]
After the client release that object, the server may used the same object to handle another client request, thus the same object to handle another client request. Thus the same object of stateless session can be shared by multiple clients But sharing the same object for multiple clients is not possible in case of state full session bean. Here server should maintain an object for every clients to handle / maintain the state of that object.
Server Side push is useful when data needs to change regularly on the clients application or browser , without intervention from client. Standard examples might include apps like Stock’s Tracker, Current News etc. As such server cannot connect to client’s application automatically. The mechanism used is, when client first connects to Server, (Either through login etc..), then Server keeps the TCP/IP connection open.
It’s not always possible or feasible to keep the connection to Server open. So another method used is, to use the standard HTTP protocols ways of refreshing the page, which is normally supported by all browsers.
<META HTTP-EQUIV=”Refresh” CONTENT=”5;URL=/servlet/stockquotes/”>
This will refresh the page in the browser automatically and loads the new data every 5 seconds.
In this post, we will see the differences b/w stateless and stateful session beans.
Stateless Session Bean:
- Stateless session bean do not maintain state across method calls and transactions
The EJB server transparently reuses instances of the Bean to service different clients at the per-method level (access to the session bean is serialized and is 1 client per session bean per method.
- Used mainly to provide a pool of beans to handle frequent but brief requests. The EJB server transparently reuses instances of the bean to service different clients.
- Do not retain client information from one method invocation to the next. So many require the client to maintain on the client side which can mean more complex client code.
- Client passes needed information as parameters to the business methods. Performance can be improved due to fewer connections across the network.
Stateful Session Bean :
- A stateful session bean holds the client session’s state.
- It is an extension of the client that creates it.
- Its fields contain a conversational state on behalf of the session object’s client.
This state describes the conversation represented by a specific client/session object pair.
- lifetime of these are controlled by the client and cannot be shared between clients.
Both are web applications used to produce web content that mean dynamic web pages. Bot are used to take the requests and service the clients. The main difference between them is, In servlets both the presentation and business logic are place it together. Where as in jsp both are separated by defining by java beans .
In jsp’s the overall code is modulated so the developer who doesn’t know about java can write jsp pages by simply knowing the additional tages and class names.
One more important to be considered is servlet take less time to compile. Jsp is a tool to simplify the process and make the process automate.
By simply include a page directives
<%@page isThreadSafe=”false” %>
To separate the code from the presentation it would be good idea to encapsulate the code in java object instantiate it and use it in our jsp. This instance is variable is called ‘id’.
We can also specific life time of this object by using ‘scope’ attribute
<jsp:useBean id=’name’ scope=”scope” class=”beanclass”/>
id: a case sensitive name is used.
Scope: The scope with in which the reference is available. page, request,session, application are possible values
page is default
class: the fully qualified classes name
bean name: The name of the java bean class
type: This type must be super class of the beans classes
Action Tag: These tags effect the run time behavior of the jsp page and the response
set back to client tags are :
<jsp: usebean> instantiate a new jsp bean class
< jsp: setProperty>: setting the properties at run time
<jsp:param>:used to sending parameters
<jsp:include>include a resource at run time
<jsp:forward>forward the control to specific resource
<jsp:plugin>:to plugin a web resource url applet
These tags effect the overall structure of the servlet that result from translation. 3 types of directives are defiend.
Page directive: used to define and manipulate the no of page dependent attributes that effect the whole jsp.
include directive: This instructs the container to include the content of the resource in the current jsp
this file is parsed once, when translation.
Taglib directive: To use tag extensions to define custom tags.
Scriptlets: There are used to include java code in jsp page these are of 3 types
scriptlet: used to write pure java code
declarations: used to declare java variables and methods
public void hello(String str)
This send the value of a java expression back to client. These results is converted to string and displayed at client.
The objects which are internal to JSP page are called implicit objects. These are available with jsp page once the jsp invoked.
1)out: used to send the content to the browser
2)Response: Represent HttpServlet Reques
3) Response: Represent HttpServletResponse
4) Page Context: used to access the objects like session, servlet context, Request, Response etc…
5) Session: Points to HttpSession objects
6) Application: Points to servlet context objects
7)Page: Points to current servlet objects
8) Exception: Points to Exception