J2EE Tutorial - Session Tracking Example
public class cart
vector1= new Vector();
public void add(String s)
public Vector showitems()
<form method=post action=carter.jsp >
WHICH PLACES DO YOU WANT TO VISIT? <BR>
The following JSP file is invoked by carter.htm ( pay particular attention to 'scope' of the bean!)
<jsp:useBean id="cart1" scope="session" class="ourbeans.cart" />
Vector vector1 =cart1.showitems();
for(int j=0; j<n; j++)
String a = (String) vector1.elementAt(j);
Copy carter.htm & carter.jsp to c:\tomcat\webapps\root directory. In Internet Explorer , we type the url as 'http://localhost:8080/carter.htm. We get the form which asks you what places you would like to visit. You can select some city and submit. You can go back and select another city and submit again. We find that city names thus selected are added to the list and displayed, thereby achieving session-tracking.
While studying EJB, the most important topic in J2EE, there will be reference to 'stateful session bean'. (ie) a session bean which has session-tracking feature. ( A stateless session bean does not retain its state).The greeter bean that we saw earlier is an example of 'stateless' bean. ( but not in EJB context).
Having thus familairized ourselves with the essential web-server techniqies, we are now ready to move on to the enterprise tier, (ie) the remote object server. This RemoteObjectServer may be either RMI server or IDL server or RMI-IIOP server . Finally, it can be an EJB server.
The core of J2EE is EJB . At present , EJB is sought to be exposed as an XML-WebService. The second group is the essence of J2EE. Though, four technologies are mentioned there (ie) RMI, IDL, RMI-IIOP and EJB, the first 3 technologies are a build up towards EJB ,the culmination.
RMI was introduced in JDK1.1 (1997)
IDL was introduced in JDK1.2 (1998)
RMI-IIOP was introduced in JDK1.3 (1999)
EJB followed closely.
Modern Enterprise Computing , in the final reckoning, is a manifestation of Distributed Objects Technology. Typically, the Enterprise Computing world is characterized by great many Operating systems and equally varied Programming languages. The operating systems may be IBM Mainframe, IBM Midframe like OS 400, Mini Computer systems (HP) , UNIX systems ( AIX of IBM, HP-UX of Hewlett-Packard, Solaris of SUN etc) , Linux & finally Desktop Windows / Mac & Mobile PALM. Such a situation may well occur even within a single organization, if it is fairly large and mature.( In other words, even an Intranet may have a multiplicity of platforms and languages). The earliest Enterprise language of the Mainframe era was COBOL. In the UNIX systems , C & later C++ reigned supreme. By 1990, Visual Basic entered the scene and gradually matured into VB.net, and it now challenges C++! In 1995, Java was released and today it is almost the default language for Enterprise world. Even in MicroSoft DotNet platform, J# is a an approved choice and so Java ( pure or tainted) can claim to be the universal language for Enterprise computing today.( J# is another incarnation of Visual J++6. but restricted to webapplications using ASP.net.)
( However, for works like device drivers, Java is not directly suitable, as it does not have pointers. Hence C/C++ are preferred for such work. But, the C/C++ routines can be wrapped in Java using JNI (Java Native Interface) and then released for the Web World. Hence, there is a great need to develop a standard, where the objects written in different languages & residing within different machines running different opearting systems can coopearte to produce the end result. Such a system will be an instance of Distributed computing.And the objects are Distributed Objects.Before the advent of Object -Oriented Programming, RPC (Remote Procedure Call) was used between different machines. This was later modified into ORPC ( Object-Oriented Remote Procedure call).
Microsoft DCOM was based on such a concept. DCOM was based on COM and COM is language -agnostic.(ie) we can create COM in any language of our choice in Microsoft platform.( At present DCOM , has been superceded by DotNet framework) . The drawback of DCOM was that it was very much platform-dependent. (ie) It worked only where both the server and client were Windows machines. Even DotNet platform is , as yet,Windows-specific.(However, DotNet WebService is able to communicate with other platforms like Unix/Linux etc by using XML .This is for the first time that it has become possible , with such ease. XML is textual and non-proprietory. XML parsers are available for all platforms. Hence the superiority of ASP.net webservice over DCOM.) And Microsoft has unceremoniuosly jettisoned DCOM.
Java is the only compiled language , so far ,which runs in a great variety of platforms. Unlike C & C++ programs , we do not have to compile the code and tweak it for each platform.This feature , besides automatic garbage collection, is the greatest merit of Java and why J2EE is the preferred choice of big companies ,which typically use OS like Mainframe, Midframe, MiniComputer, UNIX & Linux rather than Windows.
Posted on: December 18, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles